0

我的代码是这样的:

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 时,它应该说“1”时说“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();
4

1 回答 1

2

你忘记了吗?

$user_status->execute();
于 2013-05-26T22:28:17.970 回答