-1

I need to search data in the database table.

I save data in a variable, then I want to display the data using it LIKE an operator when the data is called.

This is my code :

 $data_input_user = $inFilter;
 $data_input_user = mysql_real_escape_string($inFilter);
 $sqlGetFreq = "SELECT * FROM termfrequency WHERE keyword LIKE 
 CONCAT("%",$inFilter,"%") ";
 $freqResult = mysql_query($sqlGetFreq) or die(mysql_error());

Beside that i was trying this sql query

$sqlGetFreq = "SELECT keyword, frequency FROM termfrequency WHERE keyword LIKE '%$inFilter%' ";
$freqResult = mysql_query($sqlGetFreq) or die(mysql_error());

I was trying that code, but it failed.

Any idea please?

Thanks.

Elydasian
  • 2,016
  • 5
  • 23
  • 41
  • get rid of those old mysql_ functions, use prepared statements with mysqli. Then search SO for posts that talk about "prepared statements" and "LIKE" you WILL find a pre-existing solution on SO. – mickmackusa Jun 19 '17 at 03:46
  • okey, i try now using mysqli – zordon_tri Jun 19 '17 at 03:51
  • 2
    Possible duplicate of [Correct way to use LIKE '%{$var}%' with prepared statements? \[mysqli\]](https://stackoverflow.com/questions/28385145/correct-way-to-use-like-var-with-prepared-statements-mysqli) – mickmackusa Jun 19 '17 at 03:55
  • I have tried this syntax $variabel_like = "%" . $inFilter . "%"; //$data_inputan_user = mysql_real_escape_string($inFilter); $sqlGetFreq = $variabel_like->prepare("SELECT * FROM termfrequency WHERE kata_kunci LIKE $inFilter"); $sqlGetFreq->bind_param("s",$inFilter); $sqlGetFreq->execute(); but i get error : Fatal error: Call to a member function prepare() on string in C:\xampp\htdocs\myfolder\phpfile.php – zordon_tri Jun 19 '17 at 04:13
  • that answer from Correct way to use LIKE '%{$var}%' with prepared statements? [mysqli] doesn't work in my code – zordon_tri Jun 19 '17 at 04:14
  • You must properly connect mysqli and get rid of ALL mysql_ functions. replace them with mysqli_ functions – mickmackusa Jun 19 '17 at 04:14
  • You need to delete this duplicate question, spend some time researching / educating yourself about how to use mysqli and then come back and ask your question after trying to self-solve. The answer is already on SO. – mickmackusa Jun 19 '17 at 04:15
  • Well thanks for advice and advice – zordon_tri Jun 19 '17 at 06:23
  • Your accepted solution is bad practice, as I've been trying to tell you the whole time. I'm trying to help you find the "right way" to do this. – mickmackusa Jun 19 '17 at 21:17
  • problem solved use this query : problem solved, i use this query : $sqlGetFreq = "SELECT * FROM termfrequency WHERE keyword IN ($inFilter) ORDER BY keyword,tittle_symbol"; $freqResult = mysql_query("SELECT * FROM termfrequency WHERE keyword IN ($inFilter) ORDER BY keyword,titte_symbol ASC") or die(mysql_error()); – zordon_tri Sep 05 '17 at 07:12

1 Answers1

-2

Try this

   $sqlGetFreq = "SELECT keyword, frequency FROM termfrequency WHERE keyword LIKE '%".$inFilter."%' ";

Also please set the following to track any possible error.

ini_set("display_errors", "1");
error_reporting(E_ALL);
Sehdev
  • 5,486
  • 3
  • 11
  • 34
  • ok, now nothing error, but when all mysql I replace mysqli data not display – zordon_tri Jun 19 '17 at 08:32
  • mysqli_query() takes connection variable as first parameter. You might be missing that. mysqli_query($con,$sql) – Sehdev Jun 19 '17 at 09:07
  • it solved query : problem solved, i use this query : $sqlGetFreq = "SELECT * FROM termfrequency WHERE keyword IN ($inFilter) ORDER BY keyword,tittle_symbol"; $freqResult = mysql_query("SELECT * FROM termfrequency WHERE keyword IN ($inFilter) ORDER BY keyword,titte_symbol ASC") or die(mysql_error()); – zordon_tri Sep 05 '17 at 07:12