duan19740319 2016-01-30 17:28
浏览 397

mysqli_num_rows()期望参数1为mysqli_result错误[重复]

What is the type returned by a mysqli_query, and why can't it be cast into a mysqli_result, so that I can pass it to mysqli_result?

I am creating a login page that connects to a database and validates the log in credentials. I am having trouble with the code and can't seem to figure out why I am having errors:

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in ....on line 8

 <?php

     if(isset($_POST['bttlogin'])){
        require 'connection.php';
        $email= $_POST['email'];

        $password= $_POST['password'];
        $result = mysqli_query($conn, "SELECT * FROM Users WHERE email=`$email` && password= `$password`");
        if(mysqli_num_rows($result) == 1){         
            echo "Welcome";    
        }            

        else{       

        echo "Error";
        }
     }
     ?>


     <form action = "http://raptor.kent.ac.uk/~fn40/index1.php" method= "POST">
        <table cellpadding="2" cellspacing="2" border="0">
            <tr>

                <td>Email</td>
                <td><input type="text" name="email"></td>
            </tr>
            <tr>

                <td>Password</td>
                <td><input type="password" name="password"></td>
            </tr>
            <tr>
                 <td></td>

                 <td><input type="submit" name="bttlogin" value="Login"></td>
                 <tr>
             </table>
    </form>
</div>
  • 写回答

2条回答 默认 最新

  • dongzong5017 2016-01-30 17:31
    关注

    The function mysql_query returns FALSE on failure.

    See more in the php manual:

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

    Returns FALSE on failure. For successful SELECT, SHOW, DESCRIBE or EXPLAIN queries mysqli_query() will return a mysqli_result object. For other successful queries mysqli_query() will return TRUE.

    So, there is something wrong with the query itself.

    Try:

    "SELECT * FROM Users WHERE email='{$email}' AND password='{$password}'"

    评论

报告相同问题?

悬赏问题

  • ¥15 写论文,需要数据支撑
  • ¥15 identifier of an instance of 类 was altered from xx to xx错误
  • ¥100 反编译微信小游戏求指导
  • ¥15 docker模式webrtc-streamer 无法播放公网rtsp
  • ¥15 学不会递归,理解不了汉诺塔参数变化
  • ¥15 基于图神经网络的COVID-19药物筛选研究
  • ¥30 软件自定义无线电该怎样使用
  • ¥15 R语言mediation包做中介分析,直接效应和间接效应都很小,为什么?
  • ¥15 Jenkins+k8s部署slave节点offline
  • ¥15 如何实现从tello无人机上获取实时传输的视频流,然后将获取的视频通过yolov5进行检测