can you please explain me why this code doesn't insert int the database?
//INSERT VALUES IN ORDERS
$sqlInsert = "";
for($i = 0; $i < count($_SESSION['cart']); $i++)
{
$resSelect = mysqli_fetch_assoc($sqlContent);
$prodID = $resSelect['ProdID'];
$price = $resSelect['Price'];
$quantity = $_SESSION['cart'][$resSelect['ProdID']];
$sum = ($_SESSION['cart'][$resSelect['ProdID']] *
$resSelect['Price']);
$sqlInsert .= "INSERT into Order (ProdID,
Quantity, Price, Sum, OrderID)
VALUES ($prodID, $quantity, $price, $sum, $userID);";
}
mysqli_query($dbLink, $sqlInsert);
that's the output of var_dump($sqlInsert):
INSERT INTO Order (ProdID, quantity,
Price, Sum, OrderID) VALUES (1, 4, 200, 800, 10);
INSERT INTO Order (ProdID, quantity,
Price, Sum, OrderID) VALUES (7, 3, 200, 600, 10);
INSERT INTO Order (ProdID, quantity,
Price, Sum, OrderID) VALUES (9, 3, 200, 600, 10);
this works in the database.
and the output of var_dump(mysqli_query($dbLink, $sqlInsert)) is always false.
Many thanks in Advance
ORDERis a keyword in MySQL and must be surrounded with backticks: dev.mysql.com/doc/refman/5.7/en/keywords.htmlmysqli_multi_query. It doesn't support placeholder values which makes it extremely dangerous.