所以我正在尝试登录系统,但是,我遇到了问题。
我正在使用PDOStatement::fetchAll()
函数从数据库中检索用户数据,并按预期返回此结果:
Array
(
[0] => Array
(
[id] => 1
[username] => Berk
[password] => $2y$12$.TDZWwCFfBkM.uVdUkwrVODWu6Nt8QsWMWOFXnOTFQ5CHw57pa1Cu
[discord] => Berkay#1603
[likes] => 5
[role] => Developer
[avatar] =>
[region] => Global
)
)
我的代码:
if($requestType == 'login')
{
$username = $_POST['username'];
$password = $_POST['password'];
$user = $conn->prepare("SELECT * FROM users WHERE username = :u");
$user->bindParam(':u', $username);
$user->execute();
if($user->rowCount() > 0)
{
$user->setFetchMode(PDO::FETCH_ASSOC);
$user = $user->fetchAll(PDO::FETCH_ASSOC);
print_r($user);
if(password_verify($password,$user[0]['password']))
{
// Logged in
foreach($user as $key => $value)
{
$_SESSION[$key] = $value;
print_r($_SESSION);
}
}
}
}
我的问题是,如何删除仅返回0
的第一个数组?
感谢您的帮助。
谢谢。