Jump to content

Archived

This topic is now archived and is closed to further replies.

Payback451

Weird sql query problem

Recommended Posts

I've spent quite a bit of time looking at this for the problem, and i'm completely stumped.

$Messages = mysql_query("SELECT * FROM pm WHERE to = $UserInfo[id]") or die(mysql_error());
while($Message = mysql_fetch_array($Messages)) {
[display code- no problems here]
}

Produces the following 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 'to = 1' at line 1

$UserInfo[id] is properly set to the number 1. There are 3 entries in the table pm that should be selected. Why is this producing an error? This has also happened in several other places in my script.. and the code is fine as far as I and my other coder friends can see. Was there some major update to the way mysql and php interact that would cause this to give a sytnax error? Because i have never experienced anything like this in the past.

Also, to save you all time, i've tried putting the $UserInfo[id] in quotes, tried using mysql_fetch_row, tried changing the variable name, tried selecting specific fields instead of *, tried renaming the table, and some more.

Thanks very much for your help.

Share this post


Link to post
Share on other sites
to is a [b]reserved word[/b] in MySQL and cannot be used as a field name. You ought to rename that table field something else ... or enclose it with backticks `to` [which IMO is the worst solution]

Share this post


Link to post
Share on other sites
I feel very stupid for not realizing that.. especially when my querys containing the field name 'desc' (for description) didnt work.. cmon.. I use DESC and ASC all the time.. shoulda known.

Anyway, thank you very much!

Share this post


Link to post
Share on other sites
All's well that ends well :)

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.