php - Selecting data from mysql table usinyg sql -


i have web page want user enter data in text fields should check in mysql table if category user entered text show results here php page code:

   <?php    $host  = "surveyipad.db.6420177.hostedresource.com";     $user  = "";     $pass  = "";     $database ="surveyipad";       $linkid = mysql_connect($host, $user, $pass) or die("could not connect host.");     mysql_select_db($database, $linkid) or die("could not find database.");     if (!function_exists('json_encode'))   {    function json_encode($a=false)   {   if (is_null($a)) return 'null';   if ($a === false) return 'false';   if ($a === true) return 'true';   if (is_scalar($a))   {   if (is_float($a))   {     // use "." floats.     return floatval(str_replace(",", ".", strval($a)));   }    if (is_string($a))   {     static $jsonreplaces = array(array("\\", "/", "\n", "\t", "\r", "\b", "\f", '"'), array('\\\\', '\\/', '\\n', '\\t', '\\r', '\\b', '\\f', '\"'));     return '"' . str_replace($jsonreplaces[0], $jsonreplaces[1], $a) . '"';   }   else     return $a;   }    $islist = true;    ($i = 0, reset($a); $i < count($a); $i++, next($a))   {    if (key($a) !== $i)   {     $islist = false;     break;   }   }  $result = array();  if ($islist)  {   foreach ($a $v) $result[] = json_encode($v);   return '[' . join(',', $result) . ']';  }  else  {   foreach ($a $k => $v) $result[] = json_encode($k).':'.json_encode($v);   return '{' . join(',', $result) . '}';  }  }  }      $flu=$_post['searchcode'];    $query =mysql_query("select * catalog_master category_title '%".$flu."%' ");  $rows = array();  while($row = mysql_fetch_assoc($query)) {  $rows[] = $row;  }   echo json_encode($rows);  ?> 

html page code

  <html>   <head>api testing</head>   <body>   <form  action="searchcatalog.php" method="post">   <input type="text" value="enter category"/>   <input type="submit" value="enter value"/>   </form>    </body>   </html>     

it showing error below

 warning: mysql_fetch_assoc(): supplied argument not valid mysql result resource in /home/content/i/h/u/ihus235/html/cs/pah_brd_v1/productivo/searchcatalog.php on line 63 

may problem query necessary view query , mysql error message

please try , post output

$query =mysql_query("select * catalog_master category_title '%".$flu."%' ") or die ("query error ".mysql_error()); 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

node.js - Bad Request - node js ajax post -

uitableview - Create and use custom prototype table cells in xamarin ios using storyboard -