drfu80954 2014-11-19 00:52
浏览 24

无法获取$ _POST数据进入数组[重复]

I'm creating an 11 page website all within one PHP file. On this specific part, I'm trying to take usernames from $_POST['regUser'] and put into a "logins" array defined as "$logins = array();" .

When I var_dump the array, all I get is "NULL". I'm certain I'm using the right post names and such. I realize that this code might not be near enough to diagnose my problem but I really hope it is.

Remember, this is all just a fraction of a larger program if it seems weird. This specific piece is supposed to log the user in and show the "userHome" page if they supply the correct password and add their username to the $logins array. Everything other than that is working fine. (I call the function in another part of the program)

I'm going to post a few lines of my code because I believe the problem lies somewhere within them (the whole thing is probably 400+ lines).

$regUser = $_POST['regUser'];
$regPass = $_POST['regPass'];

$goodUsername = array('user1', 'user2');
$goodUserPass = array('user1', 'user2');

$logins = array();

if (isset($_POST['userLog'])) {
    if (in_array($regUser, $goodUsername)) {
        $key = array_search($regUser, $goodUsername);
    }

    if($goodUserPass[$key] == $regPass) {
        array_push($logins, $regUser);
        echo userHome(); return;
    }
    else {
        echo invalidLogin(); return;
    }
}

function adLogins() {
    echo phpHeader();

    echo "<center><h1>User Logins</h1></center><br><br>";
    var_dump($logins);
    echo phpFooter();
}
</div>
  • 写回答

1条回答 默认 最新

  • doujiang1939 2014-11-19 00:58
    关注

    your $logins var is outside of the scope of the adLogins function

    var_dump($logins);
    

    outside of the ad logins function or pass it into the function

    function adLogins($logins){}
    
    评论

报告相同问题?

悬赏问题

  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型
  • ¥15 深度学习中的画图问题
  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条
  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件
  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了
  • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
  • ¥188 需要修改一个工具,懂得汇编的人来。