2

I have a few lines of code that should make a report about the coupons in OpenCart 1.4.9, but I can't get over 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
 'order where coupon_id = 16' at line 1.
$getcouponinfo1 = mysql_query("select * from order where coupon_id = $coupon_id")
      or die(mysql_error());

The rest of the code can be found here.

Mat
  • 202,337
  • 40
  • 393
  • 406
Alex
  • 449
  • 1
  • 4
  • 16

4 Answers4

7

order is a keyword in SQL, you need to quote that table name.

select * from `order` where ...
Mat
  • 202,337
  • 40
  • 393
  • 406
  • 1
    take a look at this link. there are some reserved words in the sql. http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html so you need to follow @Mat's answer – Subail Sunny Mar 03 '12 at 13:47
2

"order" IS A MySQL reserved word... If you need to call your table "order" then you need to enclose it in backticks (`) in your sql queries.

Your error message is not related to the query that you originally posted (prior to editing your question), but to this query:

select * from order where coupon_id = $coupon_id

and to the following query where you sum the value of the order

Mark Baker
  • 209,507
  • 32
  • 346
  • 385
2

order is a reserved keyword.

You should use `order` instead.

Pranav Hosangadi
  • 23,755
  • 7
  • 44
  • 70
Sergey Benner
  • 4,421
  • 2
  • 22
  • 29
-1

Because order is a reserved word, it is not a good name for a table

Pranav Hosangadi
  • 23,755
  • 7
  • 44
  • 70
riso
  • 232
  • 1
  • 11