MySQL:“您的SQL语法中有一个错误...在'desc)VALUES('Idea','Description')'附近" [英] MySQL: "You have an error in your SQL syntax... near 'desc) VALUES ('Idea','Description')'"

查看:185
本文介绍了MySQL:“您的SQL语法中有一个错误...在'desc)VALUES('Idea','Description')'附近"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使MySQL可以用于我的表单提交.尝试插入表格时出现问题.
当我将信息放入表单并单击提交时(在此示例中,信息在一个字段中为"Idea",在另一个字段中为"Description"),我得到以下响应:

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:

您的SQL语法有误; 检查对应的手册 您的MySQL服务器版本 在'desc)VALUES附近使用的正确语法 ("Idea","Description")在第1行"

"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"

我正在从网络服务器运行.php文件来执行此脚本.

I am running a .php file from a webserver to execute this script.

这是我当前的代码:

<?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.

推荐答案

可能是因为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.

这篇关于MySQL:“您的SQL语法中有一个错误...在'desc)VALUES('Idea','Description')'附近"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆