所以我试图存储"排名"当用户登录到控制面板时,根据给定的等级显示不同的选项。我使用了与存储和显示用户名相同的方法,该方法显示在每个页面的顶部并且工作得很好。我不能为我的生活弄清楚为什么它不会为等级值工作,但我知道它并没有在会话中保存它。这是一点不起作用;
$username = ($_POST['username']);
$password = hash('sha512', $_POST['password']);
$dbhost = 'mysql:host=██████████████████████;dbname=███████████';
$dbuser = '███████████';
$dbpassword = '████████████████';
try {
$db = new PDO($dbhost, $dbuser, $dbpassword);
$statement = $db->prepare("select password from users where email = :name");
$statement->execute(array(':name' => $username));
$result = $statement->fetch();
$pass = $result[password];
$rank = $result[rank];}
catch(PDOException $e) {echo $e->getMessage();}
if ($password == $pass) {
session_start();
$_SESSION['username'] = $username;
$_SESSION['rank'] = $rank;
header('Location: http://█████████.ca/manage.php');
}
else{
include'../../includes/head.inc';
echo '<h1>Incorrect username or password.</h1>';
include'../../includes/footer.inc';
}
我也是整个PDO的新手,因此我的密码验证方法非常粗略。
答案 0 :(得分:3)
并不是因为它没有保存排名 - 显然你没有从中检索它 查询。你只需要密码。用户名来自其他地方:
$db = new PDO($dbhost, $dbuser, $dbpassword);
$statement = $db->prepare("select password from users where email = :name");
// Should be select password, rank
$statement->execute(array(':name' => $username));
$result = $statement->fetch();
$pass = $result[password];
$rank = $result[rank];}