Search code examples
phpmysql-error-1064

How to correct Php Query for LIKE data?


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?


Solution

  • Try with this.

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