1064 - You have an error in your SQL syntax [closed]

拟墨画扇 提交于 2019-12-13 08:04:27

问题


do i have my date formated wrong?

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 
'%M-%y').', '.date('h:i:s a').', '3', '1', 'Title', 'Pr', 'BPM001')' at line 1
INSERT into names(com_id,rec_date,rec_time,rec_type,rec_request,rec_by,batch_id)
values('300','.date('%d-%M-%y').','.date('h:i:s a').','3', '1', 'Title', 'Pr', 'BPM001')

回答1:


You can try this.

$q= "INSERT into names(com_id,rec_date,rec_time,rec_type,rec_request,rec_by,batch_id) values('300', '".date("%d-%M-%y")."', '".date("h:i:s a")."', '3', '1', 'Title', 'Pr', 'BPM001')";




回答2:


It seems that you are mixing php date formatting with mysql formatting. The valid way would be this one:

$sql = "
    INSERT INTO names
    (com_id,rec_date,rec_time,rec_type,rec_request,rec_by,batch_id) 
    values('300', DATE_FORMAT('%d-%M-%y'), '".date('h:i:s a')."', '3', '1', 'Title', 'Pr', 'BPM001')
";

The recommended way would be to stick to just one of them.

$sql = "
    INSERT INTO names
    (com_id,rec_date,rec_time,rec_type,rec_request,rec_by,batch_id) 
    values('300', DATE_FORMAT('%d-%M-%y'), DATE_FORMAT('%r'), '3', '1', 'Title', 'Pr', 'BPM001')
";

OR

$sql = "
    INSERT INTO names
    (com_id,rec_date,rec_time,rec_type,rec_request,rec_by,batch_id) 
    values('300', '".date('d-F-Y')."', '".date('h:i:s a')."', '3', '1', 'Title', 'Pr', 'BPM001')
";



回答3:


try this

$q= "INSERT into names(com_id,rec_date,rec_time,rec_type,rec_request,rec_by,batch_id) values('300', '".date('%d-%M-%y')."', '".date('h:i:s a')."', '3', '1', 'Title', 'Pr', 'BPM001')";


来源:https://stackoverflow.com/questions/4334911/1064-you-have-an-error-in-your-sql-syntax

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