NameSilo

Mysql/PHP issues using WHERE

Spaceship Spaceship
Watch

Camron

VIP Member
Impact
44
I'm currently using the following code to select and get info from the database:

(I am using mysql 5 and php 5)

PHP:
$result = mysql_query("SELECT * FROM order WHERE status='pending'") or die(mysql_error());  
while($row = mysql_fetch_array( $result )) {  

<outputs the data here>

}

Now on the page it displays:

Code:
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 WHERE status='pending'' at line 1

This is really weird because I have never had such issue before. I have another script using almost identical code and it's working fine.

Any help is much appreciated :)
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
Replace
PHP:
  $result = mysql_query("SELECT * FROM order WHERE status='pending'") or die(mysql_error());
with
PHP:
  $result = mysql_query( "SELECT * FROM `order` WHERE `status`='pending'" ) or die(mysql_error());
"order" is an SQL Keyword - "ORDER BY fieldname DESC/ASC"
 
1
•••
Thanks a bunch, rep added!
 
0
•••
Camron, it would be good pratice to put `` around your field names, the better you get at creating complex queries, the easier it be to make mistakes, or use "keywords" in your queries.

=)
 
0
•••

We're social

Unstoppable Domains
Domain Recover
DomainEasy — Payment Flexibility
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back