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:
And this is the SESSION script which I will be including on all my pages that require login
if (!(ctype_digit($user) && ctype_alnum($pass)))
die("User ID and Password must be alphanumeric");
die ("Database not found".mysql_error());
$query="SELECT userid FROM user";
$query="SELECT userid FROM user
WHERE userid='$user' AND password='$pass'";
$query="SELECT firstName FROM user WHERE userid='$user'";
$query="SELECT privileged FROM user WHERE userid='$user'";
$_SESSION['privileged']=$row['privileged'] // <---- here is where I create the $_SESSION variable in question
echo "Invalid User ID/Password combonation";
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.
$privileged=$_SESSION['privileged']; //<--- this is line 12 which is generating the error