php - Error when putting Session variable in insert into query -
this question has answer here:
i'm getting error:
error: insert order (username, productname, qty) values ('denieall.joe', 'wrist watch', '1') have error in sql syntax; check manual corresponds mysql server version right syntax use near 'order (username, productname, qty) values ('denieall.joe', 'wrist watch', '1' @ line 1
<?php session_start(); include("includes/constants.php"); include("includes/functions.php"); if (!isset($_session['username'])) { redirect_to_home(); } //conection , select database: $conn = mysqli_connect(db_server,db_user,db_pass,db_name) or die("error !!!" ); foreach ($_session["cart_products"] $cart_itm) { $sql = "insert 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 me problem.
you should use backticks order
not
insert order
but
insert `order`
as other reserved word http://dev.mysql.com/doc/refman/5.6/en/keywords.html
Comments
Post a Comment