Jump to content

Archived

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

EmperorDoom

SQL syntax error??

Recommended Posts

Hey I don't know what to make of this.. one minute it was working and then it wasn't.. I got this error msg:

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 ''default' WHERE date LIKE '2006-09%'' at line 1

here's a snippet of the code

$query="SELECT * FROM '$table' WHERE date LIKE '$date%'";
$result=mysql_query($query) or DIE(mysql_error());

$table is set to 'default' and $date is set to '2006-09'
I couldn't find any answers when i searched so I appreciate any help
thanks

Share this post


Link to post
Share on other sites
Remove the single quotes('') surrounding $table ('$table') and use ``(backticks) instead. Having used a MYSQL [url=http://dev.mysql.com/doc/refman/4.1/en/reserved-words.html]reserved word[/url] as a table name you'll have to surround the name with backticks in possibly all references to the table.

Share this post


Link to post
Share on other sites
just to be clear, using backticks isn't necessary unless you are using a mysql reserved word as a table or field name, though it's good practice not to use reserved words as table/field names to begin with. 

Share this post


Link to post
Share on other sites
Agreed... just never use them, and that way, you'll find out what the reserved words are to begin with.

Share this post


Link to post
Share on other sites

×

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.