php – MySQL:“你的SQL语法错误…在’desc附近’VALUES(‘Idea’,’Description’)’”

参见英文答案 > Syntax error due to using a reserved word as a table or column name in MySQL                                    1个
我试图让MysqL为我的表单提交工作.我尝试插入表格时遇到问题.
当我将信息放入我的表单并单击提交时(在此示例中,信息在一个字段中为“Idea”,在另一个字段中为“Description”)我得到此响应:

“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 ‘desc) VALUES
(‘Idea’,’Description’)’ at line 1”

我正在从Web服务器运行.PHP文件来执行此脚本.

这是我目前的代码

PHP

MysqL_connect("localhost","root","") or die(MysqL_error());
MysqL_select_db("date_ideas") or die(MysqL_error());
$title=$_POST['title'];
$title=MysqL_real_escape_string($title);
$desc=$_POST['desc'];
$desc=MysqL_real_escape_string($desc);
$submit="INSERT INTO ideas (title,desc) VALUES ('$title','$desc');";

MysqL_query($submit) or die(MysqL_error());

echo ("Idea submitted.  Click 

如果你调用所使用的变量的回声它会成功传递信息,所以这不是问题.

最佳答案
这可能是因为desc是sql中的关键字.尝试不同的名称. desc用于按降序对结果进行排序.

一般情况下,我建议避免使用保留字作为列名.

相关文章

这篇文章主要介绍了idea中mapper快速跳转到xml插件的方法,具...
今天小编给大家分享的是IDEA搭建Maven模块化项目的实现方法,...
这篇文章主要介绍了ideaintellij怎么快速修复if语句缺少大括...
这篇文章主要介绍“idea运行main方法或Test避免编译整个应用...
这篇文章主要介绍“idea项目全局去掉严格的语法校验方式是什...
本文小编为大家详细介绍“Windows、IDEA、VSCode常用快捷键有...