到目前为止,我已经从答案中编辑了代码,但我收到了这些错误
警告:mysqli_num_rows() 期望参数 1 为 mysqli_result,布尔值在第 18 行的 C:\xampp\htdocs\Test\index.php 中给出
警告:mysqli_fetch_array() 期望参数 1 为 mysqli_result,布尔值在第 28 行的 C:\xampp\htdocs\Test\index.php 中给出
第 18 行 - $checkuser= mysqli_num_rows($query);
28号线—— while ($row = mysqli_fetch_array($query)) {
<?php
require_once('config.php');
if(isset($_POST['Login']) && isset($_POST['uname']) && isset($_POST['pass1'])) {
// Here check if all input are sent
$uname = $sql-> real_escape_string($_POST['uname']);
$pass1 = $sql-> real_escape_string($_POST['pass1']);
if ( !empty($uname) && !empty($pass1)) {
// Check if you input are not empty
$query= mysqli_query($sql, "SELECT uname, pass1 FROM login WHERE uname='$uname'");
$checkuser= mysqli_num_rows($query);
if($checkuser != 1) {
$error = "Username doesn't exist in our database!";
}
// Change $login with $query
while ($row = mysqli_fetch_array($query)) {
$checkpass= $row['pass1'];
// here i changed $pass1 to $checkpass
if ($pass1 == $checkpass) {
setcookie("user", $uname, time()+7200);
$_SESSION['user'] = $uname;
$_SESSION['start'] = time();
$_SESSION['expire'] = $_SESSION['start'] + (60 * 60 * 60);
header("Location: main.html");
exit();
} else {
$error = "Incorrect password!";
}
}
} else {
$error = "Please enter a username and password.";
}
}
?>