I’m trying to check admin privilege of the logged in user (login.php):
$sql2 = "SELECT admin FROM signup WHERE username = '$username' and password = '$password' limit 1";
if ($count == 1) {
$_SESSION['loggedin'] = true;
$_SESSION['username'] = $username;
$_SESSION['is_admin'] = (int)mysqli_query($connection, $sql2);
header("Location: ../home/index");
}
and in index.php:
<div class="main-menu">
<ul>
<li>
<?php
if (!isset($_SESSION['loggedin']) && !isset($_SESSION['username'])) {
echo "<a href='/MyProject/public/login/index'>LogIn</a>";
} else {
echo "<a href='/MyProject/public/logout/index'>Logout</a>";
echo "<li>";
if ($_SESSION['is_admin'] == 1) {
echo "<a href='/MyProject/public/admin/index'>Admin Area</a>";
echo $_SESSION['is_admin'];
echo "</li>";
}
} ?>
The problem is that session shows value of 1 (admin column) while the value in the MySQL is 0.
Whatis wrong in my code?