我不能解决这个错误:mysqli_num_rows()期望参数1是mysqli_result,布尔在
给出我只是不能解决问题。我是编程初学者,所以我希望能够得到帮助。我不能解决这个错误:mysqli_num_rows()期望参数1是mysqli_result,布尔在
if (count($errors) == 0) { $password = md5($password);
$query = "SELECT * FROM users WHERE username='$username' AND password='$password'";
$result = mysqli_query($db, $query);
if (mysqli_num_rows($result) == 1) {
$_SESSION['username'] = $username;
$_SESSION['success'] = "You are now logged in";
header('location: index.php');
}else {
array_push($errors, "Wrong username or password.");
}
}
}
回答:
问题是,如果没有返回任何内容,“SELECT”查询返回false。如果用户名和密码不正确,请拨打$result=false
。 mysqli_num_rows只接受mysqli_result对象作为参数。
你可以改变你的if语句是:
if ($result){ if (mysqli_num_rows($result) == 1) {
$_SESSION['username'] = $username;
$_SESSION['success'] = "You are now logged in";
header('location: index.php');
}
}else {
array_push($errors, "Wrong username or password.");
}
以上是 我不能解决这个错误:mysqli_num_rows()期望参数1是mysqli_result,布尔在 的全部内容, 来源链接: utcz.com/qa/257920.html