Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP session variable undefined

I have this session variable which i am trying to set to an access level when the users logs in with this:

 $accessquery = mysql_query("SELECT roleid FROM person WHERE email = '". $email ."'");
 $access = mysql_fetch_array($accessquery);

 $_SESSION['Access'] = $access;

However it says that 'Access' is undefined, what is the problem?

EDIT*

if (($_SESSION['Access']) == "2")

Error appears here

EDIT*

Session Start has been called.

like image 724
user667430 Avatar asked May 16 '26 04:05

user667430


1 Answers

Two possibilities here :

  1. Start the session by using session_start(); at the begining of page.
  2. use the following code:

    $accessquery = mysqli_query($conn, "SELECT roleid FROM person WHERE email = '". $email ."'", mysqli_store_result($conn));
    
    $access = mysqli_fetch_row($accessquery);
    
    $_SESSION['Access'] = $access[0];
    
like image 99
Ariful Islam Avatar answered May 18 '26 16:05

Ariful Islam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!