我有日期我有一个字符串日期时间我想插入到我的数据库,但我似乎得到一个语法错误,这样做
$date = '2012-11-18 23:15:12';
的字符串,我想将其插入到我的数据库。
create table A (
t_date datetime
);
,但它似乎没有工作时,我说
$q = "insert into A (t_date) values ('".$date."')";
mysql_query($q) or die("Error: ".mysql_error());
但是当我做到这一点,它返回与$日期和查询时出现错误。
我应该使用时间戳而不是日期时间吗?我将如何使它正确插入?
Error: 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 ''2012-11-18 23:15:12')' at line 1[roo
什么是确切的错误信息? – 2012-11-19 02:02:31
一般提示:如果您收到错误消息并提及获取该错误消息,请告知我们错误消息是什么。你在这里发布的代码很好。 –
测试过,[没有错误](http://sqlfiddle.com/#!2/5e282/1)。 – nickb