mysqli_num_rows()期望参数1为mysqli_result,在第87行的C:\ xampp \ htdocs \ atm \ manager \ index.php中给出的布尔值

时间:2018-11-21 07:00:11

标签: php mysqli

我使用以下命令登录时效果很好,但是在进行大型登录时出现以下错误

  

mysqli_num_rows()期望参数1为mysqli_result,在第87行的C:\ xampp \ htdocs \ atm \ manager \ index.php中给出的布尔值

<?php
    if(isset($_POST['login'])){
        $user = mysqli_real_escape_string($con, $_POST['email']);
        $pass = mysqli_real_escape_string($con, $_POST['pass']);
        $query ="select * from manager where user='$user' and pass='$pass' ";
        $res = mysqli_query($con,$query);
        if(mysqli_num_rows($res)==1) <--line 87 in my code
        {
            $query_id ="select * from manager where user='$user'";
            $run_id = mysqli_query($con,$query_id);
            $run_id2 = mysqli_fetch_array($run_id);
            $_SESSION['id'] = $run_id2['id'];
            $_SESSION['name'] = $run_id2['name'];
            echo "<script>window.open('home.php','_self');</script>";
        }
        else
        {
            echo "<script>alert('** Please Enter Correct Information **')</script>";
        }   
    }
?>

1 个答案:

答案 0 :(得分:0)

您的代码缺乏适当的错误处理-可能在调试时为您提供帮助。尝试这样做...

<?php
    if(isset($_POST['login'])){
        $user = mysqli_real_escape_string($con, $_POST['email']);
        $pass = mysqli_real_escape_string($con, $_POST['pass']);
        $query ="select * from manager where user='$user' and pass='$pass' ";
        $res = mysqli_query($con,$query);

        # $res will be FALSE on query error
        if ($res === FALSE){
            // you can also check the error message you are getting from mysql
            // var_dump(mysqli_error($con));
            // you could do a var_dump of $query here to see what exactly you pass as a query to the database.
            // var_dump($query);
            echo "<script>alert('** Query failed executing **')</script>";
        }
        elseif(mysqli_num_rows($res)==1) <--line 87 in my code
        {
            $query_id ="select * from manager where user='$user'";
            $run_id = mysqli_query($con,$query_id);
            $run_id2 = mysqli_fetch_array($run_id);
            $_SESSION['id'] = $run_id2['id'];
            $_SESSION['name'] = $run_id2['name'];
            echo "<script>window.open('home.php','_self');</script>";
        }
        else
        {
            echo "<script>alert('** Please Enter Correct Information **')</script>";
        }   
    }
?>