MySQL:“您的 SQL 语法有错误...在“desc) VALUES (“想法”、“描述”) 附近”
我正在尝试让 MySQL 为我的表单提交工作。当我尝试插入表时遇到问题。
当我将信息放入表单并单击“提交”时(在本例中,一个字段中的信息为“想法”,另一个字段中的信息为“描述”),我收到以下响应:
“您的 SQL 语法有错误; 检查对应的手册 您的 MySQL 服务器版本 在 'desc) VALUES 附近使用正确的语法 ('想法','描述')'位于第 1 行”
我正在从网络服务器运行一个 .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 <a href='Webroot/submit.php'>here</a> to go back and post another idea.");
?>
如果您调用所使用的变量的回显,它会成功地通过信息,所以这不是问题。
I am trying to get MySQL to work for my form submissions. I am having a problem when I try to insert into a table.
When I put information into my form and click submit (in this example the information is "Idea" in one field and "Description" in the other) I get this response:
"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"
I am running a .php file from a webserver to execute this script.
Here is my current code:
<?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 <a href='Webroot/submit.php'>here</a> to go back and post another idea.");
?>
If you call an echo of the variables used it succeeds at passing through the information, so that's not the problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
desc
是保留关键字(ORDER BY
中的DESCENDING
的缩写)。将其括在反引号中:
desc
is a reserved keyword (short forDESCENDING
inORDER BY
).Enlose it into backticks:
可能是因为
desc
是 SQL 中的关键字。尝试使用不同的名称。desc
用于对结果进行降序排序。一般来说,我建议避免使用保留字作为列名。
It may be because
desc
is a keyword in SQL. Try a different name.desc
is used to sort results in descending order.In general I would recommend to avoid to use reserved words for column names.