Jump to content

Error In Query.


dean7

Recommended Posts

Hi, i'm currently coding a new inbox for my website, but ive got an error which says:

 

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='NoName' ORDER BY id DESC' at line 1

 

Im not sure why ive got that as everything seems to be fine :S

 

My Code:

 

$user=$_SESSION['username'];
$get_messages = mysql_query("SELECT `id` FROM `inbox` WHERE to='$user' ORDER BY `id` DESC") or die("Error on line 9 - " . mysql_error());

 

Thanks for any help/advise given.

Link to comment
https://forums.phpfreaks.com/topic/219209-error-in-query/
Share on other sites

is 'to' the name of your column?  It's a reserved word, so you need to enclose it in back-ticks.

 

$user=$_SESSION['username'];
$get_messages = mysql_query("SELECT `id` FROM `inbox` WHERE `to`='$user' ORDER BY `id` DESC") or die("Error on line 9 - " . mysql_error());

Link to comment
https://forums.phpfreaks.com/topic/219209-error-in-query/#findComment-1136731
Share on other sites

is 'to' the name of your column?  It's a reserved word, so you need to enclose it in back-ticks.

 

$user=$_SESSION['username'];
$get_messages = mysql_query("SELECT `id` FROM `inbox` WHERE `to`='$user' ORDER BY `id` DESC") or die("Error on line 9 - " . mysql_error());

Yeah thanks, that made it work :D

Link to comment
https://forums.phpfreaks.com/topic/219209-error-in-query/#findComment-1136734
Share on other sites

Archived

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

×
×
  • 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.