-4

Possible Duplicate:
Whats wrong with this query mysql?

I am using mysql and php to update a record. Here is my code:

$n=mysql_query("UPDATE chondas SET model='$model1', yearstart=$yearstart1,
                yearstop=$yearstop1, desc='$desc1', hp='$hp1', 
                engine='$engine1',trim='$trim1', weight='$weight1' WHERE id=$id1");

In the following code if I take out desc='$desc1' everything works perfectly. What would cause this error?

When i tested the following code in phpmyadmin I got this error:

#1064 - 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='text of the textarea' at line 1.

Community
  • 1
  • 1
Ahmad Azizov
  • 166
  • 2
  • 12
  • Hey Ers. Thanks for the quick reply. I am pretty sure the error is related to mysql rather than php. Because without "desc" everything is perfect. BTW desc's length is 10,000. I don't know if it might affect that. Thanks again! – Ahmad Azizov Jan 08 '13 at 23:14

3 Answers3

3

DESC is a reserved word in mysql so you need to use backticks:

UPDATE chondas SET model='$model1', yearstart=$yearstart1, yearstop=$yearstop1, `desc`='$desc1', hp='$hp1', engine='$engine1',trim='$trim1', weight='$weight1' WHERE id=$id1

You should also switch to PDO (or mysqli) and prepared statements with bound variables to avoid potential sql injection.

jeroen
  • 91,079
  • 21
  • 114
  • 132
2

DESC is a reserved word in MySQL.

Escape it with backticks

 `desc` = '$desc1'
Zoltan Toth
  • 46,981
  • 12
  • 120
  • 134
0

Your query won't run if you include the variable names in phpMyAdmin, such as:

UPDATE chondas SET model='$model1', yearstart=$yearstart1,
yearstop=$yearstop1, **desc='$desc1'**, hp='$hp1', 
engine='$engine1',trim='$trim1', weight='$weight1' WHERE id=$id1

Also, the PHP won't run if you mix your "" and '' e.g: "UPDATE chondas SET model='$model1'...

Marius
  • 55
  • 7