简体   繁体   中英

Mysql search query with special character

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.

你忘了报价

$query = "Select post_id FROM wp_postmeta  where meta_value LIKE '".$volume."'";

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."'"; 

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.

Use single quote

LIKE ".$volume."

to

LIKE '".$volume."'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM