2012-01-18 76 views
0

出于某种原因,我的代码给了我一个错误,我不明白为什么。这里的错误:错误的MySQL语法?

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."')"; 
+0

试着把你的变量没有“。$ var”。只需做“$ var”,将所有内容保存在一行中,只是为了提高可读性。 – 2012-01-18 17:53:56

回答

4

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

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