Hey, first time posting here
I am somewhat new to PHP and I am trying to make a basic login for a web app using PHP session. The login checks the userid and pw against a mysql table and if the user is valid it will bring up a menu. The table also has a boolean value called privileged which will determine if the user has access to certain options. I am trying to create a $_SESSION variable to store that value however I am getting an error "Notice: Undefined index: privileged in /opt/lampp/htdocs/pos/possession.php on line 12"
Here is where I check the table and create session variables:
PHP Code:
<?php 
if (!(ctype_digit($user) && ctype_alnum($pass)))
    die(
"User ID and Password must be alphanumeric");
$pass=sha1($pass);
session_start();
require (
"connect.php");
$dbselect=mysql_select_db("pos",$con);
if (!
$dbselect)
    die (
"Database not found".mysql_error());
$query="SELECT userid FROM user";
$query="SELECT userid FROM user
WHERE userid='
$user' AND password='$pass'";
$result=mysql_query($query);
if (
mysql_num_rows($result)){
    
$query="SELECT firstName FROM user WHERE userid='$user'";
    
$result=mysql_query($query);
    
$row=mysql_fetch_array($result);
    
$_SESSION['user']=$row['firstName'];
    
$query="SELECT privileged FROM user WHERE userid='$user'";
    
$result=mysql_query($query);
    
$row=mysql_fetch_array($result);
    
$_SESSION['privileged']=$row['privileged'// <---- here is where I create the $_SESSION variable in question
    
header("location:menu.php");}
else{
    echo 
"Invalid User ID/Password combonation";
    
session_destroy();}
?>
And this is the SESSION script which I will be including on all my pages that require login
PHP Code:
<?php
session_start
();
if (!isset(
$_SESSION['user']))
    {
    
header("location:logIn.php");
    die;
    }
else
    {
    
$user=$_SESSION['user'];
    
$privileged=$_SESSION['privileged']; //<--- this is line 12 which is generating the error
    
}
?>
I can't seem to figure out what is causing this. I have made sure the the name of the value in the table matches with what I have in the script including case sensitive. Any help would be appreciated.