PHP session variable undefined

ぐ巨炮叔叔 提交于 2019-12-20 05:46:04

问题


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.


回答1:


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];
    



回答2:


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

print_r($any_variable);

See http://php.net/print_r




回答3:


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);



来源:https://stackoverflow.com/questions/8288807/php-session-variable-undefined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!