在php错误中搜索数据

时间:2016-12-02 03:30:32

标签: php

提前感谢任何想法?我一直试图解决这个问题,非常感谢

 <?php
    mysqli_connect("localhost","root","bsithg1","webproj") or die("Could not connect");

$output='';
    if(isset($_POST['search'])){
$searchq = $_POST['search'];
$searchq = preg_replace("#[^0-9a-z]#i","",$searchq);
$query = mysqli_query("SELECT * FROM remittancetracking WHERE TrackingNo LIKE '%$searchq%' OR amount LIKE '%$searchq%'");

$count = mysqli_num_rows($query);
if ($count == 0){
$output =   ' There was no search result';
}else{
    while($row = mysqli_fetch_array(query)){

        $ns=$row['namereceiver'];
        $cn=$row['ContactNosender'];
    $output .= '<div>'.$ns.''.$cn.'</div>'; 
    }

}

}

?>
<form method="POST">
<input type="TEXT" name="search" placeholder="Search for Tracking Number..."/>
<input type="SUBMIT" name= "" value="OK"/>
</form>
<?php print("$output");?>

它给了我这两个错误

  

(!)警告:mysqli_query()需要至少2个参数,给定1个   在第8行的C:\ wamp64 \ www \ Project \ search.php

     

(!)警告:mysqli_num_rows()期望参数1为   mysqli_result,null

搜索追踪号码......   好 没有搜索结果

1 个答案:

答案 0 :(得分:2)

变化:

mysqli_connect("localhost","root","bsithg1","webproj") or die("Could not connect");

分为:

$con = new mysqli("localhost","root","bsithg1","webproj");

然后改变:

$query = mysqli_query("SELECT * FROM remittancetracking WHERE TrackingNo LIKE '%$searchq%' OR amount LIKE '%$searchq%'");

分为:

$query = mysqli_query($con,"SELECT * FROM remittancetracking WHERE TrackingNo LIKE '%$searchq%' OR amount LIKE '%$searchq%'");

<强> WHY吗

因为您在mysqli_query

中缺少此参数
  

链接

     

仅限程序样式:mysqli_connect()或mysqli_init()返回的链接标识符

来源: http://php.net/manual/en/mysqli.query.php