MySql error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
crazymao
Forum Newbie
Posts: 14
Joined: Sun Aug 02, 2009 1:56 pm

MySql error

Post by crazymao »

i get this 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 'WHERE id=' at line 1

this is my code:
mysql_query("SELECT id,message FROM $subject WHERE id=$id") or die ('Error: '.mysql_error ());

im confused because i (think) that the problem is with the $subject because when i replace it it works (more or less) and i use it (with the $subject) in another script which works. i assign the $subject earlier in the script so what the ....
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: MySql error

Post by requinix »

Print the query before you run it - $subject is probably empty.
klevis miho
Forum Contributor
Posts: 413
Joined: Wed Oct 29, 2008 2:59 pm
Location: Albania
Contact:

Re: MySql error

Post by klevis miho »

You should make it like that:

mysql_query("SELECT id,message FROM '$subject' WHERE id='$id'") or die ('Error: '.mysql_error ());
Post Reply