【问题标题】:Error "You have an error in your SQL syntax;" near table_name错误“您的 SQL 语法有错误;”靠近表名
【发布时间】:2013-07-27 21:30:46
【问题描述】:

这是我的编码:

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`

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

【问题讨论】:

  • 表中StatusOrder 列的mysql 数据类型是什么? Datedatetime?

标签: mysql syntax tablename


【解决方案1】:

如果您想像order 一样转义reserved words in MySQL,请使用反引号而不是引号:

INSERT INTO `Order` ...

引号是字符串分隔符。

【讨论】:

  • 我也建议不要对表名使用保留字...这是不好的做法,以后会引起其他人的困惑。
  • 谢谢,订单的错误消失了:我收到了这个错误:9Pending2013-07-27 11:36:26You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '11:36:26, Pending)' at line 1
  • @Yah...gtLastName 您能否在您的代码中验证这一行 '$tanggal', '$status' 并确保它与 '$tanggal, $status 不相似
  • @Yah...gtLastName:您的 DB 表中有 Tanggal 的数据类型是什么?我猜是date。但是您正在尝试插入datetime。那是行不通的。
  • @Yah...gtLastName:如果我的猜测是对的,那么将 $tanggal=date('Y-m-d h:i:s'); 更改为 $tanggal=date('Y-m-d');
猜你喜欢
  • 2016-06-18
  • 1970-01-01
  • 2014-01-12
  • 1970-01-01
  • 1970-01-01
  • 2020-11-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多