This question already has an answer here:
I'm getting this error:
Error: INSERT INTO order (username, productName, qty) VALUES ('denieall.joe', 'Wrist Watch', '1') You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order (username, productName, qty) VALUES ('denieall.joe', 'Wrist Watch', '1' at line 1
<?php
session_start();
include("includes/constants.php");
include("includes/functions.php");
if (!isset($_SESSION['username']))
{
redirect_to_home();
}
//conection and select database:
$conn = mysqli_connect(DB_SERVER,DB_USER,DB_PASS,DB_NAME) or die("Error !!!" );
foreach ($_SESSION["cart_products"] as $cart_itm)
{
$sql = "INSERT INTO order (username, productName, qty)
VALUES ('{$_SESSION['username']}', '{$cart_itm['product_name']}', '{$cart_itm['product_qty']}')";
if (mysqli_query($conn, $sql)) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
}
mysqli_close($conn);
?>
Please help me with this problem.
</div>