Payback451 Posted June 17, 2006 Share Posted June 17, 2006 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. Link to comment https://forums.phpfreaks.com/topic/12212-weird-sql-query-problem/ Share on other sites More sharing options...
AndyB Posted June 17, 2006 Share Posted June 17, 2006 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] Link to comment https://forums.phpfreaks.com/topic/12212-weird-sql-query-problem/#findComment-46553 Share on other sites More sharing options...
Payback451 Posted June 17, 2006 Author Share Posted June 17, 2006 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! Link to comment https://forums.phpfreaks.com/topic/12212-weird-sql-query-problem/#findComment-46557 Share on other sites More sharing options...
AndyB Posted June 17, 2006 Share Posted June 17, 2006 All's well that ends well :) Link to comment https://forums.phpfreaks.com/topic/12212-weird-sql-query-problem/#findComment-46560 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.