0

我有网页,我希望用户在文本字段中输入任何数据,因此它应该在 mysql 表中检查,如果类别类似于用户输入的文本,那么这里显示的结果是我的 php 页面代码:

   <?php
   $host  = "surveyipad.db.6420177.hostedresource.com"; 
   $user  = ""; 
   $pass  = ""; 
   $database ="surveyipad"; 


   $linkID = mysql_connect($host, $user, $pass) or die("Could not connect to 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))
  {
    // Always use "." for 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;
   for ($i = 0, reset($a); $i < count($a); $i++, next($a))
  { 
  if (key($a) !== $i)
  {
    $isList = false;
    break;
  }
  }
 $result = array();
 if ($isList)
 {
  foreach ($a as $v) $result[] = json_encode($v);
  return '[' . join(',', $result) . ']';
 }
 else
 {
  foreach ($a as $k => $v) $result[] = json_encode($k).':'.json_encode($v);
  return '{' . join(',', $result) . '}';
 }
 }
 }


   $flu=$_POST['searchCode'];


 $query =mysql_query("SELECT * From catalog_Master WHERE category_Title LIKE '%".$flu."%' ");
 $rows = array();
 while($row = mysql_fetch_assoc($query)) {
 $rows[] = $row;
 }

 echo json_encode($rows);
 ?>

html页面代码

  <HTML>
  <head>API TESTING</head>
  <body>
  <form  action="searchCatalog.php" method="post">
  <input type="text" value="enter category"/>
  <input type="submit" value="Enter To Get Value"/>
  </form>

  </body>
  </HTML>    

它显示如下错误

 Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/content/i/h/u/ihus235/html/cs/pah_brd_v1/productivo/searchCatalog.php on line 63
4

2 回答 2

3

可能问题是你的查询有必要查看查询和mysql错误信息

请试试这个并发布输出

$query =mysql_query("SELECT * From catalog_Master WHERE category_Title LIKE '%".$flu."%' ") or die ("query error ".mysql_error());
于 2013-04-19T07:25:58.137 回答
1

看起来$query可能有一些错误。这就是为什么没有什么可取的。此外,您的代码不安全。您在$_POST不将其转义以进行查询的情况下输入值。

mysql_*已弃用,您应该PDO改用。

mysql_query()使用后

echo mysql_error();

并报告它显示的内容。

于 2013-04-19T07:18:44.440 回答