I have the following 2 inserts on my database, with following code:
$sql1 = "INSERT INTO order(order_id,user_id,product_id,sku,product_name,currency,price,quantity,options,value) VALUES (:orderid,:userid,:productid,:sku,:productname,:currency,:price,:quantity,:options,:value)";
$stmt1 = $conn->prepare($sql1);
for($i=0; $i < $count; $i++) {
//options
$options = array();
if(isset($_SESSION['color'.$i]) && !empty($_SESSION['color'.$i])) {array_push($options, $_SESSION['color'.$i]);}
if(isset($_SESSION['density'.$i]) && !empty($_SESSION['density'.$i])) {array_push($options, $_SESSION['density'.$i]);}
if(isset($_SESSION['diameter'.$i]) && !empty($_SESSION['diameter'.$i])) {array_push($options, $_SESSION['diameter'.$i]);}
if(isset($_SESSION['flavor'.$i]) && !empty($_SESSION['flavor'.$i])) {array_push($options, $_SESSION['flavor'.$i]);}
if(isset($_SESSION['holepitch'.$i]) && !empty($_SESSION['holepitch'.$i])) {array_push($options, $_SESSION['holepitch'.$i]);}
if(isset($_SESSION['size'.$i]) && !empty($_SESSION['size'.$i])) {array_push($options, $_SESSION['size'.$i]);}
$stmt1->bindParam(':orderid', $ordernumber, PDO::PARAM_STR);
$stmt1->bindParam(':userid', $UserID, PDO::PARAM_STR);
$stmt1->bindParam(':productid', $_SESSION['pid'.$i], PDO::PARAM_STR);
$stmt1->bindParam(':sku', $_SESSION['sku'.$i], PDO::PARAM_STR);
$stmt1->bindParam(':productname',$_SESSION['itemname'.$i], PDO::PARAM_STR);
$stmt1->bindParam(':currency',$currency, PDO::PARAM_STR);
$stmt1->bindParam(':price', $_SESSION['price'.$i], PDO::PARAM_STR);
$stmt1->bindParam(':quantity', $_SESSION['quantity'.$i], PDO::PARAM_STR);
$stmt1->bindParam(':options', $options[0], PDO::PARAM_STR);
$stmt1->bindValue(':value', $_SESSION['quantity'.$i] * $_SESSION['price'.$i], PDO::PARAM_STR);
$stmt1->execute();
//insert 2
$sql2 = "INSERT INTO shipping_cost(order_id,shipping_option,shipping_cost ) VALUES (:orderid,:shippingoption,:shippingcost)";
$stmt2 = $conn->prepare($sql2);
$stmt2->bindParam(':orderid', $ordernumber, PDO::PARAM_STR);
$stmt2->bindParam(':shippingoption', $shippingoption, PDO::PARAM_STR);
$stmt2->bindParam(':shippingcost', $shippingcost, PDO::PARAM_STR);
$stmt->execute();
} //end for
The above query resulted in the following PDOException with message:
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(order_id,user_id,product_id,sku,product_name,currency,price,quantity,optio' at line 1'
I am unable to understand what is wrong with the PDO statement above.
Requesting help. Thanks in advance.