Web Hosting Talk







View Full Version : Having PHP trouble with what should be a simple MySQL Query


GA PunkFreak
05-26-2006, 03:41 PM
Hello,

I'm having trouble running the following query:


$editquery = "UPDATE `nyk_players` SET firstname = '$firstname', lastname = '$lastname', status = '$status', number = '$number', height = '$height',
weight = '$weight', dateofbirth = '$dateofbirth', yearspro = '$yearspro', yearsknicks = '$yearsknicks', position1 = '$position1', position2 = '$position2', from = '$from',
strengths = '$strengths', weaknesses = '$weaknesses', bio = '$bio', acquisition = '$acquisition', highlights = '$highlights',
knicknames = '$knicknames', headphotourl = '$headphotourl', actionphotourl = '$actionphotourl' WHERE id = '$id'";

$editresult = mysql_query($editquery) or die ("Error in query: $editquery. " . mysql_error());



I get the following error:
Error in query .......
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 'from = 'Arizona', strengths = 'Great mid-range jumper; Good shotblocker; Athleti' at line 3

I don't see anything wrong at that part in the code. What could be wrong?

Thanks,
-Phil

orbitz
05-26-2006, 03:43 PM
from = '$from',

'from' is a reserved word in mysql

Christopher Lee
05-26-2006, 05:58 PM
from = '$from',

'from' is a reserved word in mysql

orbitz is right. You might want to enclose from in backticks to see if that will work, but really, you should change the name of that field.


`from`='$from'

Xorlev
05-27-2006, 05:11 PM
Backticks will escape it correctly, but I agree. Change the name of the field to origin, or hometown, or something that won't disagree with MySQL and still shows its meaning.

BlueShadow
05-27-2006, 05:41 PM
Just for future reference, here's the list of reserved words (http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html) that you should avoid using.

moe88
05-28-2006, 06:12 PM
Hey,
I had the same trouble when i had the field mode. First i used backticks, but it got wiersome to remember everytime to type them in, so I just changed the name.

-Moe

thartdyke
05-29-2006, 12:43 AM
Not that you're asking :-), but you'll probably want to put strengths and weaknesses into a separate table. As it is, your table isn't 1st order normalised (the values in the strengths and weaknesses fields are not atomic).

If you ever want to find out (say) who the good shot blockers are, you are making things difficult for yourself (as well as risking poor data integrity)