How do I store my data in session array into my database ? Upon entering the product and its quantity, the user will be directed to a checkout page. In the checkout page, upon filling up the necessary information in a form, I am trying to use a button to submit the session array into my database.
My current code:
<?php
session_start();
$array = $_SESSION['shopping_cart'];
$connect = mysqli_connect('localhost', 'root', '', 'table');
?>
$sql = "INSERT INTO customer_order (productName, quantity, totalPrice, pax)";
foreach($array as $product){
$sql = "INSERT INTO p2_5.customer_order (productName, quantity, totalPrice, pax)";
$sql .= " VALUES ('{$product['name']}', '{$product['quantity']}', '{$product['price']}', '{$product['pax']}')";
if ($connect->query($sql)) {
$errorMsg = "Connection failed: " . $connect->connect_error;
$success = false;
}
}
However, upon clicking on the button, I am able to store client information into my database, but I would have an PHP error message Undefined index: name, Undefined index: quantity, Undefined index: price, Undefined index: pax ?

json_encode()or usingserialize()?>. 2) you're passing elements from$arraywithout referencing to theirindex, I mean without$array[0]or$array[1]$array