Question

I am getting a error in my PHP query. I am attempting to do the below query. However, when I put the the code in PHP. The data is not pulling the "like" data. The search I want:

"SELECT * FROM `TABLE` WHERE `ID` like \'NAME%\'";

My php code:

$TABLE= $_POST['cptCode1'];
$data = mysql_query("SELECT * FROM TABLE WHERE ID like'".$searchName."'") or die(mysql_error()); 

What am I doing wrong?

Was it helpful?

Solution

Try with this.

$data = mysql_query("SELECT * FROM TABLE WHERE ID like '".$searchName."%'") or die(mysql_error()); 

OTHER TIPS

I guess a space and % missing:

like '".$searchName."%'"
    $data = mysql_query("SELECT * FROM TABLE WHERE ID LIKE '$searchName%'");

Or Check here how-to-use-php-string-in-mysql-like-query

Follow this, it works

Replace

$data = mysql_query("SELECT * FROM TABLE WHERE ID like'".$searchName."'") or die(mysql_error()); 

with

$data = mysql_query("SELECT * FROM TABLE WHERE ID like '".$searchName."%'") or die(mysql_error()); 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top