NameSilo

Mysql/PHP issues using WHERE

SpaceshipSpaceship
Namecheap AuctionsNamecheap Auctions
Namecheap AuctionsNamecheap Auctions
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.
GoDaddyGoDaddy
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
•••
Dynadot — .com TransferDynadot — .com Transfer
Truehost — .com domains from $4.99, hosting includedTruehost — .com domains from $4.99, hosting included

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com
Catchy
DomDB
NameFit
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back