Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 14th Apr 2011, 05:49 AM   #1
Active Warrior
 
David Reed's Avatar
 
Join Date: 2006
Location: , , United Kingdom.
Posts: 45
Thanks: 17
Thanked 1 Time in 1 Post
Default
PHP not querying a specific table in mysql?!
Share on: 
fb share twitter share gplus share more share

Hi everyone

I'm getting an error when I try to query a specific table:

"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 'order' at line 1"

My code has and does work perfectly on all of my other tables in the same database, which is why I'm so confused about it :confused:

This is the code that's throwing an error:

$dispatch = mysql_query("SELECT * FROM order")or die(mysql_error());

but it is worded exactly the same as my other tables.

I checked the storage engines of each of the tables in PHPmyadmin,
all are innoDB...

Just completely stuck here.. any help would be appreciated
David Reed is offline  
Unread 14th Apr 2011, 06:05 AM   #2
Active Warrior
 
David Reed's Avatar
 
Join Date: 2006
Location: , , United Kingdom.
Posts: 45
Thanks: 17
Thanked 1 Time in 1 Post
Default
Re: PHP not querying a specific table in mysql?!
Share on: 
fb share twitter share gplus share more share

Nevermind, I fixed the problem now.

Just to let everyone know, the problem was the table name. I just changed it from 'order' to 'orderstatus' and now it's working.

I should have thought that using the word order as a table name would cause mySQL some headaches.....
David Reed is offline  
Unread 14th Apr 2011, 06:06 AM   #3
PHP Developer
War Room Member
 
Join Date: 2010
Location: World
Posts: 79
Thanks: 14
Thanked 6 Times in 6 Posts
Blog Entries: 2
Lightbulb
Re: PHP not querying a specific table in mysql?!
Share on: 
fb share twitter share gplus share more share

"order" is a reserved keyword.

Use this instead (notice the backtick)
PHP Code:
 = mysql_query("SELECT * FROM `order`")or die(mysql_error()); 
Update : oh okay you can just rename the table instead

Hello world
xrvel is offline  
The Following User Says Thank You to xrvel For This Useful Post:
Unread 14th Apr 2011, 06:12 AM   #4
Active Warrior
 
David Reed's Avatar
 
Join Date: 2006
Location: , , United Kingdom.
Posts: 45
Thanks: 17
Thanked 1 Time in 1 Post
Default
Re: PHP not querying a specific table in mysql?!
Share on: 
fb share twitter share gplus share more share

Originally Posted by xrvel View Post

"order" is a reserved keyword.

Use this instead (notice the backtick)
PHP Code:
 = mysql_query("SELECT * FROM `order`")or die(mysql_error()); 
Update : oh okay you can just rename the table instead
That's even better, now I don't have to change any of my data diagrams. Damned uni and their strict guidelines.

Thanks
David Reed is offline  
Unread 14th Apr 2011, 07:08 AM   #5
VIP Warrior
War Room Member
 
SteveJohnson's Avatar
 
Join Date: 2007
Location: Caldwell, Idaho, USA.
Posts: 1,967
Thanks: 1,024
Thanked 2,043 Times in 1,183 Posts
Default
Re: PHP not querying a specific table in mysql?!
Share on: 
fb share twitter share gplus share more share

here's one for your bookmark folder: MySQL :: MySQL 5.1 Reference Manual :: 8.3 Reserved Words

The 2nd Amendment, 1789 - The Original Homeland Security.

Gun control means never having to say, "I missed you."
SteveJohnson is offline  
Closed Thread


Bookmarks

Tags
mysql, php, querying, specific, table


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 09:06 AM.