0

If i have a variable like

   $volume = 'IV, no. 33';
   $query = "Select post_id FROM wp_postmeta  where meta_value LIKE ".$volume." 

It show 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 ' no. 33

So what is the correct way for search with special characte.

Rajendra Yadav
  • 645
  • 3
  • 12

4 Answers4

0

You forgot quotes

$query = "Select post_id FROM wp_postmeta  where meta_value LIKE '".$volume."'";
Yogesh Suthar
  • 30,424
  • 18
  • 72
  • 100
0

You have to put quotes around your string value

$volume = 'IV, no. 33';
 $query = "Select post_id FROM wp_postmeta  where meta_value LIKE ".$volume." 

Should be

$volume = 'IV, no. 33';
$query = "Select post_id FROM wp_postmeta  where meta_value LIKE '".$volume."'"; 
Hanky Panky
  • 46,730
  • 8
  • 72
  • 95
0

Use the below code:

 $volume = 'IV, no. 33';
 $query = "Select post_id FROM wp_postmeta  where meta_value LIKE '".$volume."'"; 

Use the single quota to tell the query that it is a string.

Code Lღver
  • 15,573
  • 16
  • 56
  • 75
0

Use single quote

LIKE ".$volume."

to

LIKE '".$volume."'
Code Lღver
  • 15,573
  • 16
  • 56
  • 75
Goutam Pal
  • 1,763
  • 1
  • 10
  • 14