drllqg2903
2011-11-27 20:33
浏览 40
已采纳

PHP会话变量未定义

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.

图片转代码服务由CSDN问答提供 功能建议

我有这个会话变量,我试图在用户登录时设置为访问级别:< / p>

  $ accessquery = mysql_query(“SELECT roleid FROM person WHERE email ='”。$ email。“'”); 
 $ access = mysql_fetch_array($ accessquery); 
  
 $ _SESSION ['Access'] = $ access; 
   
 
 

然而它说'Access'未定义,有什么问题? \ n

EDIT *

  if(($ _SESSION ['Access'])==“2”)
   \  n 
 

此处出现错误

编辑*

已启动会话开始。

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

3条回答 默认 最新

  • duan19805 2011-11-27 20:40
    最佳回答

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

相关推荐 更多相似问题