title: php mysqli login - after login the titlebar does not change according to the userlevel
body: <p>Hi all i am a newbie in php. I have made a login script which does not show any error when the page loads. It logs in and redirects to the profile page and but the titlebar does not change according to userlevel I checked made changes based on tutorials i watched but there is no success. </p>
  
  <p>Here is my code.</p>
  
  <p>Connection to database:</p>
  
  <pre><code>&lt;?php
  //error_reporting(0);
  session_start();?&gt;
  &lt;?php
  $con = new mysqli('localhost', 'root', '', 'tl');
  if($con-&gt;connect_errno &gt; 0){
      die('Sorry, We\'re experiencing some connection problems.');
  }
  ?&gt;
  </code></pre>
  
  <p>Functions:</p>
  
  <pre><code>&lt;?php
      function loggedin(){
          if(isset($_SESSION['user_id'])){
              return true;
          }else{
              return false;
          }
      }
  ?&gt;
  </code></pre>
  
  <p>Titlebar:</p>
  
  <pre><code>    &lt;div&gt;
      &lt;?php
          if(loggedin()==true){
              $user_id=$_SESSION['user_id'];
              $log=$con-&gt;prepare("SELECT username,user_level FROM users WHERE user_id='$user_id'");
              $log-&gt;execute;
              $log-&gt;bind_result($username, $user_level,$user_id);
              $log-&gt;store_result;
              if($log-&gt;fetch()) //fetching the contents of the row
              {
                  if($user_level=='a'){?&gt;
                      &lt;a href = 'index.php'&gt;Home&lt;/a&gt;
                      &lt;a href = 'profile.php'&gt;Profile&lt;/a&gt;
                      &lt;a href = 'admin.php'&gt;Admin&lt;/a&gt;
                      &lt;a href = 'index.php'&gt;Log Out&lt;/a&gt;
                  &lt;?php
                  }if($user_level=='m'){?&gt;
                      &lt;a href = 'index.php'&gt;Home&lt;/a&gt;
                      &lt;a href = 'profile.php'&gt;Profile&lt;/a&gt;
                      &lt;a href = 'index.php'&gt;Log Out&lt;/a&gt;
                  &lt;?php
                  }
              }?&gt;
          &lt;?php
          }?&gt;&lt;a href = 'index.php'&gt;Home&lt;/a&gt;
                      &lt;a href = 'login.php'&gt;Login&lt;/a&gt;
                      &lt;a href = 'register.php'&gt;Register&lt;/a&gt;
          &lt;?php}
      ?&gt;
  
  &lt;/div&gt;
  </code></pre>
  
  <p>Index Page:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;LOGIN&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;?php include 'connect.php';?&gt;
  &lt;?php include 'functions.php';?&gt;
  &lt;?php include 'titlebar.php';?&gt;
  Index
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Login Page:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;LOGIN&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;?php include 'connect.php';?&gt;
  &lt;?php include 'functions.php';?&gt;
  &lt;?php include 'titlebar.php';?&gt;
  
  &lt;h3&gt;LOGIN HERE:&lt;/h3&gt;
  &lt;form action ="" method="post"&gt;
  
  User Name:&lt;br/&gt;
  &lt;input type='text' name='username' /&gt;
  &lt;br/&gt;&lt;br/&gt;
  Password:&lt;br/&gt;
  &lt;input type='password' name='password' /&gt;
  &lt;br/&gt;&lt;br/&gt;
  &lt;input type='submit' name='submit' value='login'&gt;
  &lt;/form&gt;
  &lt;?php
  
  if(isset($_POST['submit'])){
      $username = $_POST['username'];
      $password = md5($_POST['password']);
  
  
      $stmt = $con-&gt;prepare("SELECT user_id, username, password, status FROM users WHERE username=? AND password=? LIMIT 1");
      $stmt-&gt;bind_param('ss', $username, $password);
      $stmt-&gt;execute();
      $stmt-&gt;bind_result($user_id, $username, $password, $status);
      $stmt-&gt;store_result();
      if($stmt-&gt;num_rows == 1)  //To check if the row exists
          {
              if($stmt-&gt;fetch()) //fetching the contents of the row
              {
                 if ($status == 'd') {
                     echo "YOUR account has been DEACTIVATED.";
                     exit();
                 } 
                 if ($status == 'b') {
                     echo "YOUR account has been BANNED.";
                     exit();
                 } 
                 if ($status == 'n') {
                     echo "YOUR account has NOT YET BEEN ACTIVATED.";
                     exit();
                 } 
                 else {
                     $_SESSION['loggedin'] = 1;
                     $_SESSION['user_id'] = $user_id;
                     $_SESSION['username'] = $username;
                      header('Location: index.php');
                      exit();
                 }
             }
  
      }
      else {
          echo "INVALID USERNAME/PASSWORD Combination!";
      }
      $stmt-&gt;close();
  }
  else 
  {   
  
  }
  $con-&gt;close();
  
  ?&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Profile Page:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;PROFILE&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;?php include 'connect.php';?&gt;
  &lt;?php include 'functions.php';?&gt;
  &lt;?php include 'titlebar.php';?&gt;
  PROFILE&lt;/br&gt;
  &lt;?php
  if (isset($_SESSION['loggedin']) &amp;&amp; $_SESSION['loggedin'] == true) {
      echo "Welcome to the member's area, " . $_SESSION['username'] . "!";
  } else {
      echo "Please log in first to see this page.";
  }
  ?&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Logout:</p>
  
  <pre><code> &lt;?php
   include 'connect.php';
   include 'functions.php';
   session_destroy();
   header('location: index.php');
   ?&gt;
  </code></pre>
  
  <p>Is there any thing i should change to make this work. After logging in the title bar does not change to admin or member menu. Any help will be appreciated.</p>
  
  <p>Thank You.</p>