PDA

View Full Version : one-line php MYSQL mystery!!! (well, for me anyhow...)



eyebum
April 20th, 2009, 02:16 PM
Hey there folks,
I have a php/mysql site that is working pretty good. I can add/update/delete and display data pretty much at will. Which makes my problem that much more of a mystery to me! Maybe one of you kind folks here can spot my error.

Ok. simple insert into a database. Why does this line work:
$query="INSERT INTO $table (Division, Handler, Dog, event, Club, order) VALUES ('$Division', '$Handler', '$Dog', '$Event', '$Club', '$order')";

and yet, this line doesn't!:
$query="INSERT INTO $table (Division, Handler, Dog, event, Club) VALUES ('$Division', '$Handler', '$Dog', '$Event', '$Club')";

As you see, the only difference is one field, and the corresponding data!
The answer to your first question is yes, the field does exist. The 'order' field is type "int(4)". So is the 'event' field, and no problems there.
Here's the error:
""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 'order) VALUES ('division1', 'John Smith', 'Spot', '137', 'ClubA', '299')' at line 1"

??? I am mystified.

rondog
April 20th, 2009, 04:06 PM
ORDER is a reserved key word in MySQL. Change the field name and you should be golden. I've made this mistake more than once :P

eyebum
April 20th, 2009, 05:19 PM
ORDER is a reserved key word in MySQL. Change the field name and you should be golden. I've made this mistake more than once :P

Wow! Monumental DUH!!!!!!!!
Understand perfectly, and quick fix!
Thank you very much Wicked!
:}