MySQL语法不正确?

时间:2012-01-18 17:51:10

标签: mysql sql

出于某种原因,我的代码给了我一个错误,我无法弄清楚原因。这是错误:

INSERT INTO organization (org_name, add_1, add_2, city, state, zip, url, email, phone, contact, hours, file_loc, notes, description, group) VALUES('testmi', '333', '', '', 'MI', '', 'www.blah.com', '', '888-999-2222', '', '', '', '', '', 'Michigan')QUERROR 3You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'group) VALUES('testmi', '333', '', '', 'MI', '', 'www.blah.com', ''' at line 1

这是代码:

$sqlInsertOrg = "INSERT INTO organization (org_name, add_1, add_2, city, state, zip, url, email, phone, contact, hours, file_loc, notes, description, group)
             VALUES('".$org_name."', '".$add_1."', '".$add_2."', '".$city."', '".$state."', '".$zip."', '".$url."', '".$email."', '".$phone."', '".$contact."', '".$hours."', '".$file_loc."', '".$notes."', '".$description."', '".$group."')";

1 个答案:

答案 0 :(得分:4)

GROUP是MySQL中的保留关键字。用反引号(`)来逃避它,你会没事的。

INSERT INTO organization (org_name, ... `group`) ...