I am using core php with mysql for my project. I am stuck in session part. I cant undestand how to create session for username to display his name after login. i tried so many times but failed. please help me with the same. Below is my code for insertUser.php. where total 3 queries for login. I am working on second query for superadmin. As u noticed in my code i create session for username for superadmin. I include menubar.php , header.php and sidebar.php in home.php. I want to add session in menubar.php and header.php.
insertUser.php
<?php
include 'db.php';
if (isset($_REQUEST['insert'])) 
    {
        $acc_name = $_REQUEST['username'];
        $acc_email = $_REQUEST['email'];
        $acc_pass = $_REQUEST['password'];
        $role_id = $_REQUEST['roleid'];
        $sql = mysqli_query($conn,"INSERT INTO `accountants`(`acc_name`, `acc_email`, `acc_pass`, `roleId`) VALUES ('".$acc_name."','".$acc_email."','".$acc_pass."','2')");
        if ($sql>0) 
            {
                header('Location: home.php');
                echo 'data added successfully';
            }
        $row = mysqli_query('SELECT * FROM `accountants`');     
        $data = mysqli_fetch_array($row);
        $data = mysqli_num_rows($conn,$data);
        $_SESSION['role'] = $data['roleId'];
    }
if (isset($_REQUEST['submit'])) 
{
        $username = $_REQUEST['user'];
        $password = $_REQUEST['pass'];
        $sql = mysqli_query($conn,"SELECT * FROM `accountants` where `acc_email` = '".$username."' AND `acc_pass` = '".$password."'");
        $data = mysqli_fetch_array($sql);        
        $_SESSION['role']=$data['roleId'];
        $_SESSION['username']=$data['acc_name'];
        $sql1 = mysqli_query($conn,"SELECT * FROM `superadmin` where `username` = '".$username."' AND `password` = '".$password."'");
        $data02 = mysqli_fetch_array($sql1);        
        $_SESSION['role']=$data02['roleId'];
        $sql2 = mysqli_query($conn,"SELECT * FROM `member` where `email` = '".$username."' AND `password` = '".$password."'");
        $data01 = mysqli_fetch_array($sql2);        
        $_SESSION['role']=$data01['roleId'];
        $_SESSION['username']=$data01['fname'];
        if ($data01>0) 
        {
            header('Location: DigitalSociety - Member/production/societyList.php');    
        }
        elseif ($data>0) 
            {
                header('Location: societyList.php');
            }
       elseif ($data02>0) {
            $_SESSION['login_user']=$username;
                header('Location: DigitalSociety - Superadmin/production/societyList.php');
       }
       else
            {
                header('Location: index.php');
                echo 'incorrect login';
            }
}
?>
menubar.php
<div class="profile clearfix">
  <div class="profile_pic">
    <img src="images/img.jpg" alt="..." class="img-circle profile_img">
  </div>
  <div class="profile_info">
    <span>Welcome,</span>
    <h2><?php echo $_SESSION['login_user'];?></h2>
  </div>
</div>
I i used above code for displaying username it shows error Undefined variable: _SESSION in
please help me with the same.
 
     
     
     
     
     
    