简体   繁体   English

MySQL错误1064-但是没有错误?

[英]MySQL Error 1064 - but no misstake?

I'dont understand this: 我不明白这一点:

I will update a mysql database. 我将更新一个mysql数据库。

mysql_query("UPDATE image Set title = '".$ed1."', desc = '".$ed2."', cat = '".$ed3."', privacy = '".$ed4."' WHERE id = '".$id."'");

But it shows: 但它显示:

ERROR 1064 错误1064

and: 和:

You have an error in your SQL syntax; 您的SQL语法有误; check the manual that corresponds to your MySQL server version for the right syntax to use near desc = [...] 检查与您的MySQL服务器版本相对应的手册,以在desc = [...]附近使用正确的语法

EDIT: Thanks for reply. 编辑:感谢您的答复。 I've renamed the name! 我已经改名了! Now it works ;) 现在可以了;)

DESC is a reserved word in SQL. DESC是SQL中的保留字。 You'll need to quote it if you want to use it: 如果要使用它,则需要引用它:

mysql_query("UPDATE `image` Set `title` = '".$ed1."', `desc` = '".$ed2."', `cat` = '".$ed3."', `privacy` = '".$ed4."' WHERE `id` = '".$id."'");

You should try to avoid using reserved words for field names if you can; 如果可以的话,应尽量避免在字段名称中使用保留字。 there's a list here: http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html 这里有一个列表: http : //dev.mysql.com/doc/refman/5.0/en/reserved-words.html

You should also look at migrating from mysql_* functions, as they're being deprecated. 您还应该考虑从mysql_*函数进行迁移,因为它们已被弃用。 You should look at using PDO or mysqli instead - they both help you write much more secure SQL. 您应该考虑使用PDO或mysqli-它们都可以帮助您编写更加安全的SQL。

DESC is a reserved word in MySQL . DESCMySQL中保留字 You need to escape it with backticks. 您需要使用反引号将其转义。 Try 尝试

UPDATE image Set title = '".$ed1."', `desc` = ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM