问题
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