PHP 插入不能正常工作
我的文件中有以下几行 PHP 代码以及其他一些代码:
$command = "INSERT INTO inventory_items (Index, Name, Price) VALUES (NULL, 'Diamond', '3.99')";
$insertion = mysql_query($command) or die(mysql_error());
if ($insertion == FALSE)
{
echo "Error: Insert failed.";
}
else
{
echo "Insert successful.";
}
它不断返回此错误:
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 'Index, Name, Price) VALUES (NULL, 'Diamond', '3.99')' at line 1
myAdmin 说我正在使用 MySQL 客户端版本 5.0.91。我做错了什么?我就是想不通!我尝试了很多搜索...
I have the following lines of PHP code in my file along with some other code:
$command = "INSERT INTO inventory_items (Index, Name, Price) VALUES (NULL, 'Diamond', '3.99')";
$insertion = mysql_query($command) or die(mysql_error());
if ($insertion == FALSE)
{
echo "Error: Insert failed.";
}
else
{
echo "Insert successful.";
}
It keeps returning this 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 'Index, Name, Price) VALUES (NULL, 'Diamond', '3.99')' at line 1
myAdmin says I am using MySQL client version 5.0.91. What am I doing wrong? I just can't figure it out! I tried searching a lot...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
索引是 MySQL 中的保留字,因此,您需要更改列的名称,或者使用反引号对其进行转义。试试这个
$command
:在这里阅读有关保留字的更多信息:http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html
Index is a reserved word in MySQL and as such, you need to either change the name of the column, or escape it with backticks. Try this
$command
:Read more about reserved words here: http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html
试试这个:
MySQL 保留字以及如何处理它们 。
Try this:
MySQL reserved words and how to treat them.
您能否验证 inventory_items 表中的列是否为:
并且您已将 Index 字段设置为 AUTO_INCRMENT。
最好的办法可能是从插入语句中删除该字段。
尝试一下,
因为您无论如何都没有插入索引。
希望有帮助!
Can you verify that the columns in your inventory_items table are:
And that you have the Index field set to AUTO_INCREMENT.
The best thing is probably to remove that field from your insert statement.
Try
Since you're not inserting an Index anyway.
Hope that helps!