douliang2167 2015-09-15 09:35
浏览 20
已采纳

不知怎的,这个数组不是数组?

The following code return some results that are baffling me...

if(is_array($loginUser)) {         
    $_SESSION['name'] = $loginUser['firstname'];
    $_SESSION['id'] = $loginUser['id'];
    print_r($_SESSION['name']);
    print_r($loginUser);
    var_dump($loginUser[1]);
    exit();
    header("Location: ../index.php?page=home");
}

That returns:

Notice: Undefined index: firstname in wwwroot/includes/userhandler.php on line 124

Notice: Undefined index: id in wwwroot/includes/userhandler.php on line 125

Array ( [0] => Array ( [0] => 4 [id] => 4 [1] => Johnny [firstname] => Johnny [2] => Appleseed [lastname] => Appleseed [3] => ja@ja.com [email] => ja@ja.com [4] => johnny'shashedpassword [password] => johnny'shashedpassword ) ) 

Notice: Undefined offset: 1 in wwwroot/includes/userhandler.php on line 129

NULL

  • 写回答

2条回答 默认 最新

  • dongyong9224 2015-09-15 09:39
    关注

    The id and firstName are stored in an array with key 0

    change

    $_SESSION['name'] = $loginUser['firstname'];
    $_SESSION['id'] = $loginUser['id'];
    

    to

    $_SESSION['name'] = $loginUser[0]['firstname'];
    $_SESSION['id'] = $loginUser[0]['id'];
    

    but I see no reason why the you have an extra dimension in your $loginUser array. Try to refactor the way $loginUser is building its array

    Later in the code you are calling var_dump($loginUser[1]); This returns your second error message because there is only a $loginUser[0]

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图