[SOLVED] You have an error in your SQL syntax

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
robster
Forum Contributor
Posts: 360
Joined: Wed Jul 16, 2003 8:28 am
Location: Sunshine Coast, Australia

[SOLVED] You have an error in your SQL syntax

Post by robster »

Hi there, I've read the sticky forum post and tried the suggestions before asking this question, but 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 'lines ORDER BY id DESC' at line 1

at this line of code:

Code: Select all

$result = mysql_db_query($dbname, "SELECT * FROM lines ORDER BY id DESC") or die(mysql_error());
I'm a bit lost now, I just can't see what I've done wrong. $dbname variable is the correct database and lines is the correct table.

Too strange, I'd really appreciate any suggestions.

Thanks :)

Rob
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

'lines' is a mysql reserved word. So either rename the column or backquote it, eg `lines`
User avatar
robster
Forum Contributor
Posts: 360
Joined: Wed Jul 16, 2003 8:28 am
Location: Sunshine Coast, Australia

Post by robster »

thank you so much!

:)

I changed it to another name and it worked a treat. Wow, no wonder I couldn't see the syntax error :)

Thanks again.

Rob
User avatar
robster
Forum Contributor
Posts: 360
Joined: Wed Jul 16, 2003 8:28 am
Location: Sunshine Coast, Australia

Post by robster »

I don't suppose 'to' 'from' or 'draw' are also reserved words?
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

User avatar
robster
Forum Contributor
Posts: 360
Joined: Wed Jul 16, 2003 8:28 am
Location: Sunshine Coast, Australia

Post by robster »

thank you again, and thanks for that link. Very helpful :)
Post Reply