0

I have this query

$query = "SELECT * FROM customers WHERE customer_name = '{$orders}'";

but when the value of the $orders have a single quote(') for example:

$orders = "Carlo's shop";

the query return an error.

is there any good way to handle this situation?

A.B
  • 20,110
  • 3
  • 37
  • 71
jhunlio
  • 2,550
  • 4
  • 26
  • 45

1 Answers1

3

Use PDO with prepared statements. See reference docs.

$query = $pdo->prepare('SELECT * FROM customers WHERE customer_name= :orders');

$query->execute(array('orders' => $orders));

Dharman
  • 30,962
  • 25
  • 85
  • 135
A.B
  • 20,110
  • 3
  • 37
  • 71
  • thank your clever answer, this part `'$orders'` not work for me, but your answer give me an idea how to make my code working.. a very big thanks. happy codding... – jhunlio Dec 09 '14 at 03:02