1

Trying to echo ONLY if the users rank in database is = to 2

So it echos it even if its rank is 0 and I don't know why. Here is my code.

    <?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 Answers1

0

Look at this statement here,

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

It should be,

if($row2['rank'] == 2) {
Rajdeep Paul
  • 16,887
  • 3
  • 18
  • 37
  • @RyanSeecrest Glad I could help. Cheers! ;-) You've been given answers here, please consider marking the correct answer as *accepted answer*. [How to accept answer on Stack Overflow](http://meta.stackexchange.com/a/5235) – Rajdeep Paul Feb 13 '16 at 05:21