I have ran into a problem when passing a the result of SQL Query as a variable than as a session across all pages.
I currently have the "username" being passed as a session and that works but I have tried to set up a "privledge level" as a session exactly the same but this doesn't work while the "username" does.
I have tested the mySQL query on the database within phpmyadmin and it works fine, any help with this would be apprecated as I have been going round in circles.
SELECT privledge_lvl FROM `users` WHERE username='$username'
Result:
|privledge_lvl|
---------------
|2            |
Login.php
<?php
        require('db.php');
        session_start();
    // If form submitted, insert values into the database.
    if (isset($_POST['username'])){
                $username = stripslashes($_REQUEST['username']); // removes backslashes
                $username = mysqli_real_escape_string($con,$username); //escapes special characters in a string
                $password = stripslashes($_REQUEST['password']);
                $password = mysqli_real_escape_string($con,$password);
        //Checking is user existing in the database or not
        $query = "SELECT * FROM `users` WHERE username='$username' and password='".md5($password)."'";
                $result = mysqli_query($con,$query) or die(mysqli_error());
                $rows = mysqli_num_rows($result);
        $privquery = "SELECT privledge_lvl FROM `users` WHERE username='$username'";
                $privresult = mysqli_query($con,$privquery) or die(mysqli_error());
        if($rows==1){
                        $_SESSION['username'] = $username;
                        $_SESSION['privledgelvl'] = $privresult;
                        header("Location: index.php"); // Redirect user to index.php
            }else{
                                echo "<div class='form'><h3>Username/password is incorrect.</h3><br/>Click here to <a href='login.php'>Login</a></div>";
                                }
    }else{
?>
auth.php
<?php
session_start();
if(!isset($_SESSION["username"])){
header("Location: login.php");
exit(); }
?>
index.php
<p>Welcome <?php echo $_SESSION['username']; ?>!</p>
<p>Privledge Level <?php echo $_SESSION['privledgelvl']; ?></p>
 
    