Jump to content

SQL Syntax Error?


Stalingrad

Recommended Posts

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.