1

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?

Jaync31
  • 27
  • 9

4 Answers4

1

Try with this.

$data = mysql_query("SELECT * FROM TABLE WHERE ID like '".$searchName."%'") or die(mysql_error()); 
Jenz
  • 8,172
  • 7
  • 41
  • 75
0

I guess a space and % missing:

like '".$searchName."%'"
Sahil Mittal
  • 20,515
  • 12
  • 60
  • 89
0
    $data = mysql_query("SELECT * FROM TABLE WHERE ID LIKE '$searchName%'");

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

Community
  • 1
  • 1
Himanshu
  • 4,269
  • 16
  • 29
  • 37
0

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()); 
Birlla
  • 1,520
  • 2
  • 14
  • 17