我的代码是:
if(isset($_SESSION['id']) && isset($_SESSION['username'])){
$user_status = $db->prepare("SELECT `user_status` FROM `users` WHERE `id` = :id AND `username` = :username");
$user_status->bindValue(":id",$_SESSION['id'],PDO::PARAM_STR);
$user_status->bindValue(":username",$_SESSION['username'],PDO::PARAM_STR);
$user_status = $user_status->fetchColumn();
if($user_status == 0){
header("Location: /logout");
}elseif($user_status == 8 || $user_status == 9){
$links = '(<a href="/admin/index">Admin</a>)';
}
}
当我执行$ user_status的var_dump时,它应该说“bool(false)”,因为它是数据库中的默认user_status。
我有登录脚本检查用户是否也被禁止,并且完全正常:
$check_banned = $db->prepare("SELECT `user_status` FROM `users` WHERE `username` = :username");
$check_banned->bindValue(":username",$_POST['username'],PDO::PARAM_STR);
$check_banned->execute();
$check_banned = $check_banned->fetchColumn();
答案 0 :(得分:2)
你忘记了吗?
$user_status->execute();