I am trying to make an SQL query where it only selects data from the table if the userID matches for that of the session and that of the table. 

My problem is that it doesn't acknowledge a userID variable associated with the session and returns a blank string. It also does this for fName, lName and password but not for others including username and level which it gets these values from the database and displays the correct ones associated with the session. Why are some columns names working in my code but not others? 

I have tried echoing the userID out and nothing but when I echo the username out it displays it. 

```
<?php
    session_start();
    include "connection.php";
    if(!isset($_SESSION["username"])){
        header("Location: login.php");
    }
    $userID = $_SESSION["userID"];
    $sql = ("SELECT * FROM users WHERE userID = '$userID'");
    $result = mysqli_query($con, $sql);

    if (mysqli_num_rows($result) > 0) {
       while($row = mysqli_fetch_assoc($result)) {
          echo "ID: " . $row["userID"]. ";
        } 
    }
    else{
         echo "No records";
    }
?>

```

That's just a part of my code and I was just borrowing the if statement from W3Schools to check things to see if they would work

adminPage.php

```
<?php
    session_start();
    echo $_SESSION ["level"];

    if(isset($_SESSION["username"])){
        if($_SESSION["level"] != "admin"){
            header("Location: users.php");
        }
        else{
            header("Location: adminPage.php");
        }
    }
?>

```

login.php 

```
<?php
    if (!isset($_SESSION["username"])){
        echo"
        <p class = \"big\"> Login </p>
        <hr>
        <form action = \"loginInsert.php\" method = \"post\">
            Username: <input type = \"text\" name = \"username\"><p>
        Password: <input type = \"password\" name = \"password\"><p>
        <button type = \"submit\" value = \"Submit\"/> Sign in </button>
        <hr>
        Not a member? <a href = \"signUp.php\"><button type = \"button\"> Sign Up </button></a>
        </p>
        </form>";
    }
    else{
        header("Location: admin.php");
    }           
?>

```

loginInsert.php

```
<?php
    session_start();
    include "connection.php";
    if(isset($_POST["username"])){
        $username = $_POST["username"];
    }
    if(isset($_POST["password"])){
        $password = $_POST["password"];
    }

    $sql = "SELECT * FROM users WHERE username = '$username' and password = '$password'";
    $result = mysqli_query($con, $sql);

    $row = mysqli_fetch_assoc($result);

    if(mysqli_num_rows($result) == 1){
        $_SESSION["username"] = $username;
        $_SESSION["level"] = $row ["level"];
        if ($_SESSION["level"] == "admin"){
            header("Location: admin.php");
        }
        else{
            header("Location: users.php");
        }
    }
    else{
    header("Location: login.php");
    }
?>

```

![enter image description here](https://i.stack.imgur.com/43JqT.jpg)
Thank you for taking time to read my question