Sql error occurred when I'm trying this query

Here is the query

 $query_order = "select * from orders where key = '$pay_key'";

Error shown

SELECT 
    * 
FROM `orders` 
where `key` = 'C90320'

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 'key = 'C90320'' at line 1*

Upvotes: 2

Views: 59

Answers (3)

M.I.T.
M.I.T.

Reputation: 1042

try this

first of all you need to compare it using string so code should like this

 $query_order = "select * from orders where `key` = '".$pay_key."'";

Upvotes: 0

Mudassir Hasan
Mudassir Hasan

Reputation: 28751

 $query_order = "select * from orders 
                 where `key` = '".mysqli_real_escape_string($pay_key)."'";

Upvotes: 0

Praveen Kumar Purushothaman
Praveen Kumar Purushothaman

Reputation: 167182

key is a reserved word. Change your query to:

$query_order = "select * from orders where `key` = '$pay_key'";

Also, I would recommend escaping the $pay_key's value. Say something like:

$pay_key = mysqli_real_escape_string($pay_key);

Upvotes: 1

Related Questions