我有下面的代码:奇怪的MySQL错误。 (PHP)
<?php
include("config.php");
$key = 'blahblah';
$sql = "INSERT INTO softversions SET key='$key'";
$result = mysql_query($sql) or die ($mysql_error());
echo "dude";
?>
这给了我一个错误:
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 'key='svksskjfvns'' at line 1
的事情是,我已经在其他页面,并使用这个脚本约一百倍工作。 表和字段名称是100%正确的。
我不明白是怎么回事。 你看到那里的语法错误吗?
认为应该是:'INSERT INTO softversions(键)VALUES( '$键')' – Clive
您使用SET为UPDATE语句不是INSERT语句。我非常怀疑这个脚本,因为你在其他任何地方都可以使用它。 – Garvin
@Garvin你实际上可以使用'INSERT INTO .. SET ..'。这是一个老问题:http://stackoverflow.com/questions/861722/mysql-insert-into-table-values-vs-insert-into-table-set。 – Marcus