<?php
//include 'globals.php';
$mysqli = new mysqli(correct...);
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: " . $mysqli->connect_error();
}
$username = $_POST['username'];
$password = $_POST['password'];
if($query = $mysqli->prepare("SELECT password FROM users WHERE username = ?"))
{
$query->bind_param("s", $username);
$query->execute();
//$query->store_result();
$result = $query->num_rows;
echo sprintf("Row: %d", $result);
if($result != 0)
{
$row = $query->fetch_array();
if(password_verify($password, $row["password"]))
{
echo 'Success';
}
else
{
echo 'Failed';
}
}
else
{
echo 'Empty';
}
}
$mysqli->close();
?>
如果我不执行store_result(),则该行将始终返回0(也许查询出错了?) 但是,如果我在PHPMYADMIN上执行查询,则效果很好。
我想念什么?
答案 0 :(得分:0)
找到了解决方案。
相反
Header
要做
$query = $mysqli->prepare("SELECT password FROM users WHERE username = '?'");
感谢所有贡献者。希望这对其他人有帮助。