仅在用户在数据库中排名时才尝试回显= = 2

时间:2016-02-13 05:12:12

标签: php mysqli pdo

仅在用户在数据库中排名为= 2

时才尝试回显

即使它的等级为0而且我不知道为什么,它也会回响它。这是我的代码。

    <?php
        $query299 = "SELECT * from users WHERE username = '" . $_SESSION['user']['username'] . "'";
        $stmt2 = $db->prepare($query299);
        $stmt2->execute();
        $row2 = $stmt2->fetch();
        if($row2['rank'] = 2) {
            echo '
                <li>
                    <a href="admin.php">
                    <i class="fa fa-cog"></i>
                    <span>Admin</span>
                    </a>
                </li>
            ';
        }
?>

1 个答案:

答案 0 :(得分:0)

请看这里的陈述,

if($row2['rank'] = 2) { ...
                 ^ you're doing assignment, not comparison

应该是,

if($row2['rank'] == 2) {