Warrior Forum - The #1 Digital Marketing Forum & Marketplace

Warrior Forum - The #1 Digital Marketing Forum & Marketplace (https://www.warriorforum.com/)
-   Programming (https://www.warriorforum.com/programming/)
-   -   PHP not querying a specific table in mysql?! (https://www.warriorforum.com/programming/364440-php-not-querying-specific-table-mysql.html)

David Reed 14th April 2011 05:49 AM

PHP not querying a specific table in mysql?!
 
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 :o

David Reed 14th April 2011 06:05 AM

Re: PHP not querying a specific table in mysql?!
 
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.....

xrvel 14th April 2011 06:06 AM

Re: PHP not querying a specific table in mysql?!
 
"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 ;)

David Reed 14th April 2011 06:12 AM

Re: PHP not querying a specific table in mysql?!
 
Quote:

Originally Posted by xrvel (Post 3704267)
"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 :D

SteveJohnson 14th April 2011 07:08 AM

Re: PHP not querying a specific table in mysql?!
 
here's one for your bookmark folder: MySQL :: MySQL 5.1 Reference Manual :: 8.3 Reserved Words


All times are GMT -6. The time now is 12:45 AM.