3

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.

4
  • 1
    Where does it say that? Did you remember to start the session? Commented Nov 27, 2011 at 20:34
  • Post the code where you have the error. Commented Nov 27, 2011 at 20:34
  • 1
    I don't see where the access is being defined nor do I see session_start(); Commented Nov 27, 2011 at 20:35
  • You should really watch out for SQL injections with code like this. If this were production code, your site would be hacked within 2 minutes. Commented Nov 27, 2011 at 20:50

3 Answers 3

6

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];
    
Sign up to request clarification or add additional context in comments.

Comments

0

To figure out what's going on, I recommend you to use

print_r($any_variable);

See http://php.net/print_r

Comments

0

Did you call session_start();?

Try to debug your code with just a fixed value: $_SESSION["Test"]="test"; and then do a var_dump($_SESSION);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.