我无法打印 msqli_result
I cannot get msqli_result to print
我的登录系统目前运行良好。我可以输入正确的用户名和密码,它会登录,但反之则不然。唯一不能正常工作的是状态检查。如果用户的状态为“0”,则不应登录。所以我试图打印出状态但没有显示。然后我对 password_hash 做了同样的事情,我得到了相同的结果(这很奇怪,因为 password_verify() 没有问题)。用户输入的密码确实会打印出来,所以这一定是 mysqli_result 的事情。有帮助吗?
include_once($_SERVER['DOCUMENT_ROOT'] . "/php_scripts/db_conx.php");
function CheckLogin($username, $password, $db_conx){
time_nanosleep(0, 100000000);
$userQuery = $db_conx->prepare("SELECT * FROM users WHERE username = ?");
$userQuery->bind_param('s', $username);
$userQuery->execute();
$userResult = $userQuery->get_result();
if($userResult->num_rows == 1){
$password_hash = $userResult->fetch_assoc()['password'];
$status = mysqli_fetch_assoc($userResult)['status']; // $status turns out null
echo($status); // Prints nothing
printf("%s\n", $userResult->fetch_assoc()['password']); // Prints nothing
print_r($userResult->fetch_assoc()); // Prints nothing
print($password); //Prints the password correctly
if(password_verify($password, $password_hash) && $status != '0'){
//password_verify() works like a charm
//Status check is the only thing that does not work
return true;
} else{
return false;
}
}
return false;
}
用户的状态为“0”,因此不应登录。
您将光标前进了 4 个位置,但可能只有 1 行。 fetch
只使用一次并赋值。
$row = $userResult->fetch_assoc();
然后你可以分配你的变量。
$password_hash = $row['password'];
$status = $row['status'];
他们将可以访问。
您也可以只检查查询中的状态:
SELECT * FROM users WHERE username = ? and status <> 0
或
SELECT * FROM users WHERE username = ? and status = 1
我的登录系统目前运行良好。我可以输入正确的用户名和密码,它会登录,但反之则不然。唯一不能正常工作的是状态检查。如果用户的状态为“0”,则不应登录。所以我试图打印出状态但没有显示。然后我对 password_hash 做了同样的事情,我得到了相同的结果(这很奇怪,因为 password_verify() 没有问题)。用户输入的密码确实会打印出来,所以这一定是 mysqli_result 的事情。有帮助吗?
include_once($_SERVER['DOCUMENT_ROOT'] . "/php_scripts/db_conx.php");
function CheckLogin($username, $password, $db_conx){
time_nanosleep(0, 100000000);
$userQuery = $db_conx->prepare("SELECT * FROM users WHERE username = ?");
$userQuery->bind_param('s', $username);
$userQuery->execute();
$userResult = $userQuery->get_result();
if($userResult->num_rows == 1){
$password_hash = $userResult->fetch_assoc()['password'];
$status = mysqli_fetch_assoc($userResult)['status']; // $status turns out null
echo($status); // Prints nothing
printf("%s\n", $userResult->fetch_assoc()['password']); // Prints nothing
print_r($userResult->fetch_assoc()); // Prints nothing
print($password); //Prints the password correctly
if(password_verify($password, $password_hash) && $status != '0'){
//password_verify() works like a charm
//Status check is the only thing that does not work
return true;
} else{
return false;
}
}
return false;
}
用户的状态为“0”,因此不应登录。
您将光标前进了 4 个位置,但可能只有 1 行。 fetch
只使用一次并赋值。
$row = $userResult->fetch_assoc();
然后你可以分配你的变量。
$password_hash = $row['password'];
$status = $row['status'];
他们将可以访问。
您也可以只检查查询中的状态:
SELECT * FROM users WHERE username = ? and status <> 0
或
SELECT * FROM users WHERE username = ? and status = 1