So i'm creating a webshop project at the moment and i ran into a problem. I ask the user to add items in a shopping cart (which is a session array). After the user has decided what to buy, the user can place an order for those items. First the user will have to give some information to what address the user wants the package to be sent. This data is sent to the table 'orders' and this works fine, here i give the order an ID. Immediately after this I try to fill the orderdetails in with that same orderID:
The following code is resposible for reading out the data from the session array and then writing that same information in the table 'orderdetails'
$query2 = "INSERT INTO orderdetails (OrderID, productID, UnitPrice, Quantity) VALUES ($orderID, $productID, $UnitPrice, $Quantity)";
if (!empty($_SESSION["shopping_cart"])) {
$orderID = mysqli_insert_id($conn);
foreach ($_SESSION["shopping_cart"] as $keys => $values) {
$productID = $values["item_productID"];
$UnitPrice = $values["item_price"];
$Quantity = $values["item_quantity"];
mysqli_query($conn, $query2);
}
mysqli_close($conn);
}