'PDOException' Syntax error or access violation: 1064 You have an error in your SQL syntax; check

ぃ、小莉子 提交于 2021-02-16 20:28:48

问题


I keep getting the following error when trying to submit details of an order into my database:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 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 ' in /home/ubuntu/workspace/handlers/checkout-handler.php on line 111 PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 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_details, order_address, cust_id, cust_name, delivery_type, paid) ' at line 1.

I can't figure out whats wrong with it, all of the variables are being posted correctly to the page.

$query1 = "INSERT INTO order (order_details, order_address, cust_id, cust_name, delivery_type, paid) VALUES(:details,:address,:d,:name,:delivery,:paid);";                                         
$sql=$conn->prepare($query1);
$sql->bindParam(':details', $details);
$sql->bindParam(':address', $address);
$sql->bindParam(':name', $name);
$sql->bindParam(':delivery', $delivery_type);
$sql->bindParam(':paid', $paid);
$sql->bindParam(':d', $d);
$sql->execute();

回答1:


order is a reserved keyword. You should add backticks ` around it to use it:

$query1 = "INSERT INTO `order` (order_details, order_address, cust_id, cust_name, delivery_type, paid) 
           VALUES(:details,:address,:d,:name,:delivery,:paid);";                                         
$sql = $conn->prepare($query1);

See also : Keywords and Reserved Words



来源:https://stackoverflow.com/questions/49829971/pdoexception-syntax-error-or-access-violation-1064-you-have-an-error-in-your

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!