I'm a little confused, PHP says $results is a non-object of the mysqli class

后端 未结 5 1984
北恋
北恋 2020-12-22 13:01

I\'m trying to fetch results using mysqli->fetch_row() (or fetch_object(), fetch_array()), yet when I go to run the code at run time it gives me the following error:

5条回答
  •  醉梦人生
    2020-12-22 13:16

    You script is lacking error checking, and therefore the error in the query is not handled.

        $query = "SELECT user, password FROM Users 
        WHERE user = '$user' AND password = '$pass' " ;
        //           ^ quotes needed     
    
        echo $query;
    
        $results = $db->query($query);
    
        // handle a error in the query
        if(!$results)
          die($db->error);
    
        while ($row = $results->fetch_row()){
            echo htmlspecialchars($row->user);
            echo htmlspecialchars($row->password);
        }
    

提交回复
热议问题