错误“您的SQL语法中有错误;”靠近table_name

时间:2013-07-27 21:30:47

标签: mysql syntax tablename

这是我的编码:

session_start();
include 'Connect.php';
$userid=$_SESSION['userid'];
$tanggal=date('Y-m-d h:i:s');
$status='Pending';  

echo $userid;
echo $status;
echo $tanggal;

mysql_query("INSERT INTO 'Order' (IdPelanggan,Tanggal,StatusOrder) VALUES ('$userid', '$tanggal', '$status')") or die (mysql_error());

运行编码后,我收到了这个错误:

 `9Pending2013-07-27 11:25:54You 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 (IdPelanggan,Tanggal,StatusOrder) VALUES (9, 2013-07-27 11:25:54, Pending)' at line 1`

我想知道我的错误在哪里。

1 个答案:

答案 0 :(得分:4)

如果你想像order一样逃离reserved words in MySQL,那么请使用反引号而不是引号:

INSERT INTO `Order` ...

引号是字符串分隔符。