Stalingrad Posted July 30, 2008 Share Posted July 30, 2008 hello! I'm trying to program a personal messaging system on my site, and I keep on getting an error that says this: 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 'for='Sonya'' at line 1 I looked at the query, and even tried a few things, but I still get this error. I have no clue what could possibly be wrong with the query, as it seems fine to me. Here's the code for the messaging system. messages.php: <?php session_start(); include("config.php"); if(session_is_registered("un")) { echo "<div id=\"n\">$nav</div><div id=\"i\">$info</div><div id=\"c\"><font size=6>Messages</font><br><br><table border=\"1\" bordercolor=\"black\" cellpadding=\"5\" cellspacing=\"0\"><tr><td><center>Title</center></td><td><center>From</center></td><td><center>Status</center></td></tr>"; $query = "SELECT * FROM `messages` WHERE for='$sun'"; $recset = mysql_query($query) or die(mysql_error()); if(mysql_num_rows($recset) < 1) { echo "<i>You don't have any Messages.</i>"; } else { while($row = mysql_fetch_assoc($recset)) { $q = mysql_query("SELECT * FROM messages WHERE for='$sun'"); while($i = mysql_fetch_array($q)) { $mid = $i['messageid']; $for = $i['for']; $from = $i['from']; $title = $i['title']; $status = $i['status']; } echo "<tr><td><center><a href=messages.php?messageid=$mid>$title</a></center></td><td><center><a href=lookup.php?username=$from>$from</a></center></td><td><center>$status</center></td></tr>"; } } echo "</div>"; } if(!session_is_registered("un")) { echo "<div id=\"n\">$nav1</div><div id=\"i\"></div><div id=\"c\">Error! Please <a href=login.php>Login</a> or <a href=register.php>Register</a> to Continue.</div>"; } ?> Also; the error is coming from the first query, not the other one. Any help ius greatly appreciated, and thank you in advance! Link to comment https://forums.phpfreaks.com/topic/117411-sql-syntax-error/ Share on other sites More sharing options...
revraz Posted July 30, 2008 Share Posted July 30, 2008 FOR is a Mysql Reserved Word, so either don't use it as a Fieldname (best) or use `backticks` around it (not advised). Link to comment https://forums.phpfreaks.com/topic/117411-sql-syntax-error/#findComment-603923 Share on other sites More sharing options...
Stalingrad Posted July 30, 2008 Author Share Posted July 30, 2008 Thank You! =] Link to comment https://forums.phpfreaks.com/topic/117411-sql-syntax-error/#findComment-603924 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.