奇怪的 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% 正确。
我不明白发生了什么事。 您看到那里的语法错误了吗?
I have a following code:
<?php
include("config.php");
$key = 'blahblah';
$sql = "INSERT INTO softversions SET key='$key'";
$result = mysql_query($sql) or die ($mysql_error());
echo "dude";
?>
This gives me an error:
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
The thing is that I've used this script about a hundred times on other pages and it worked.
Table and field names are 100% correct.
I don't understand what is going on.
Do you see the syntax error there?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
key
是MySQL中的保留字。要将其用作列,每次调用时都需要对其进行转义。key
is a reserved word in MySQL. To use it as a column, you need to escape it every time you call it.$sql = "插入 softversions(keyName) 值('{$key}')";
$sql = "INSERT INTO softversions(keyName) values('{$key}')";
KEY
是一个保留字 在 MySQL 中,您需要使用反引号将其转义以将其用作列名,并且在插入时也不应该使用SET
。KEY
is a reserved word in MySQL and you need to escape it using backticks to use it as a column name and also you should not useSET
when inserting.