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
  • 19,005
  • 3
  • 31
  • 64
jhunlio
  • 2,438
  • 3
  • 24
  • 43

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
  • 26,923
  • 21
  • 73
  • 125
A.B
  • 19,005
  • 3
  • 31
  • 64
  • 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