0

我不断收到此错误,无法找出问题所在。任何帮助,将不胜感激。谢谢。

sql -"INSERT INTO practices (order,name,url) VALUES ('1','Business & Corporate Law','business-corporate-law')"

错误:1064You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order,name,url) VALUES ('1','Business & Corporate Law','business-corporate-law')' at line 1

这是php:

$sql =  "INSERT INTO ".$table." (".$cols.") VALUES (".$vals.")";
$result = mysql_query($sql);
if(!$result){die('Error: ' . mysql_errno() . mysql_error());}

$table 为“practices”,$cols 为“order,name,url”,$vals 为“'1','Business & Corporate Law','business-corporate-law'”

4

1 回答 1

2

order是 SQL 中的关键字,因此如果将其用作列名(或一般的标识符),则必须将其包装如下:

INSERT INTO practices ( `order`, `name`, `url` ) 
  VALUES ('1','Business & Corporate Law','business-corporate-law')
于 2012-05-18T20:07:56.597 回答