简体   繁体   中英

MySQL Error 1064 - but no misstake?

I'dont understand this:

I will update a mysql database.

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

But it shows:

ERROR 1064

and:

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 = [...]

EDIT: Thanks for reply. I've renamed the name! Now it works ;)

DESC is a reserved word in 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

You should also look at migrating from mysql_* functions, as they're being deprecated. You should look at using PDO or mysqli instead - they both help you write much more secure SQL.

DESC is a reserved word in MySQL . You need to escape it with backticks. Try

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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