Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 警告:mysqli_num_rows()需要参数1_Php_Mysql_Mysqli - Fatal编程技术网

Php 警告:mysqli_num_rows()需要参数1

Php 警告:mysqli_num_rows()需要参数1,php,mysql,mysqli,Php,Mysql,Mysqli,警告:mysqli_num_rows()要求参数1为mysqli_结果,第63行的C:\xampp\htdocs\test4\server.php中给出的字符串 替换 // LOGIN USER if (isset($_POST['login_user'])) { $username = ($_POST['username']); $password = ($_POST['password']); if (empty($username)) { arra

警告:mysqli_num_rows()要求参数1为mysqli_结果,第63行的C:\xampp\htdocs\test4\server.php中给出的字符串

替换

// LOGIN USER
if (isset($_POST['login_user'])) {
    $username = ($_POST['username']);
    $password = ($_POST['password']);

    if (empty($username)) {
        array_push($errors, "Username is required");
    }
    if (empty($password)) {
        array_push($errors, "Password is required");
    }

    if (count($errors) == 0) {
        $password = md5($password);
        $query = "SELECT * FROM users WHERE username='$username' AND password='$password'";
        $results =( $query);

        if (mysqli_num_rows($results) == 1) {
            $_SESSION['username'] = $username;
            $_SESSION['success'] = "You are now logged in";
            header('location: index.php');
    }else {
            array_push($errors, "Wrong username/password combination");
        }
    }
} 


如果(mysqli_num_rows($results)==1),问题不在第63行{相反,问题在$results=($query)之前的行;您没有在那里执行查询。根据您的代码,我无法给出确切的答案,但应该是:$results=$mysqli->query($query);此处的更多信息:请不要使用您自己的密码哈希,特别是不要使用
MD5()
SHA1()
。PHP提供并请出于用户的安全考虑使用它们。您的脚本是开放的。甚至您也应该考虑在
MYSQLI_uquot>或
PDO
API中使用,而不是串联值
$results = ($query);
$results = mysqli_query($query);