多个Where子句在php中导致布尔错误

时间:2018-04-04 10:36:50

标签: php html mysql

当我尝试在积压搜索框中搜索任何内容时,在我提交我的值之前,会产生2个错误,如下所示: -

  

警告:mysqli_num_rows()期望参数1为mysqli_result,   在C:\ xampp \ htdocs \ SOPHOMORE \ coursereginfo.php中给出的布尔值在线   53

     

警告:mysqli_fetch_array()期望参数1为mysqli_result,   在C:\ xampp \ htdocs \ SOPHOMORE \ coursereginfo.php中给出的布尔值在线   54

<!doctype html>  
<html>  
<?php include'abcadmin.css' ?> 

<body>  
    <br>
    <br>
    <br>
    <br>
    <h4><object align="right" width="190"><a href ="studentlogin.php" onclick="alert('You have logged out successfully!!;') <?php session_destroy(); ?>">Logout</a></object></h4>
    &nbsp;
    &nbsp;
    &nbsp;
    &nbsp;
    <br>
    <br>
    <br>
    <br>
     <center><h1>Course Information</h1></center>  
 &nbsp;
&nbsp;

<form method="POST">  
<center><h4>Backlog(Subject Code):</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="text" name="bl1"><br><br><br>
<center><input type="submit" value="Submit" name="submit" /> </center>

</form>  

<?php


    session_start();
    global $un,$pw,$stuname,$stusurname,$stuemail,$cou,$backlog1,$backlog2,$backlog3,$backlog4,$backlog,$x;
    $sapid=$_SESSION['adminstusapid'];
    $con=mysqli_connect('localhost','root','') or die(mysqli_error());  
    mysqli_select_db($con,'sophomore') or die("cannot select DB");
    $query=mysqli_query($con,"SELECT * FROM student_subjects WHERE SAPID='".$sapid."'");
    $query1=mysqli_query($con,"SELECT * FROM student_registration WHERE sap_id='".$sapid."'" );
    $numrows=mysqli_num_rows($query);
    $numrows1=mysqli_num_rows($query1);
    $sapidinfo=array();

    if(isset($_POST["submit"])){

    $search=$_POST['bl1'];
    $query2=mysqli_query($con,"SELECT * FROM sbmp_subjects WHERE subject_code='".$search."'" );
    $numrows2=mysqli_num_rows($query2);
    while($row2 = mysqli_fetch_array($query2))
    { 
      $backlog=$row2['subject'];
    }
    $query3=mysqli_query($con,"SELECT * FROM student_subjects WHERE (Subject1='".$backlog."' OR Subject2='".$backlog."' OR Subject3='".$backlog."' OR Subject4='".$backlog."' OR Subject5='".$backlog."' OR Subject6='".$backlog."' OR Subject7='".$backlog."'" );
    $numrows3=mysqli_num_rows($query3);
    while($row3 = mysqli_fetch_array($query3))
    { 
      $sapidinfo[]=$row3;
    }
    echo '<table class="a" align="center" border="1">';
    echo '<tr>';
    echo '<td>';
    echo '<h4>';
    echo "SAP ID";
    echo '</h4>';
    echo '</td>';
    echo '</tr>';
    echo '</table>';
    echo "<br>";

for($x=0; $x<$numrows3; $x++)
{
    echo '<table class="e" align="center" border="1">';
    echo '<tr>';
    echo '<td>';
    echo '<h4>';
    echo $sapid[$x];
    echo '</h4>';
    echo '</td>';
    echo '</tr>';
    echo "<br>";

}
}

?>

</body>
</html>

1 个答案:

答案 0 :(得分:0)

我认为您查询返回了错误。来自php.net

  

失败时返回FALSE。对于成功的SELECT,SHOW,DESCRIBE或EXPLAIN查询,mysqli_query()将返回一个mysqli_result对象。对于其他成功的查询,mysqli_query()将返回TRUE。

你必须在应用mysqli_num_rows和mysqli_fetch_array之前检查exitcode。也来自php.net

if ($result = mysqli_query($link, "SELECT Code, Name FROM Country ORDER BY Name")){

$row_cnt = mysqli_num_rows($result);

printf("El resultado tiene %d filas.\n", $row_cnt);

mysqli_free_result($result);}