dongxie8906 2013-04-27 03:59
浏览 35
已采纳

在使用$ _POST单击检查按钮后,使用$ _POST方法以前设置的数组变量将丢失

please forgive my confusing title, here is my problem:

  1. set an array variable through $_POST
  2. check which button has been clicked and process the $_POST variable

What is in my code:

<?php
...
$user = array_filter(array_map('array_filter', $_POST['user']));
...

$submit = isset($_POST['button']) ? trim($_POST['button']) : '';
   if ($submit == 'Confirm') {

        ...do something with $user;

   } else if ($submit == 'Cancel') {

        ...do something else with $user;

   }
?>

It appears that when the page is first loaded, $user has been set correctly, however, once the "Confirm" button is clicked, the $name array is lost and cannot be processed. Any idea of how to resolve this will be much appreciated! Many thanks.

  • 写回答

1条回答 默认 最新

  • dongyisa6254 2013-04-27 04:06
    关注

    an Idea, you need to store it in session. it seems you get $_POST['user'] from previous page/request. variable $_POST only used for passing variable between page, It will not exist anymore if you reload the page.

    do it like:

    $user = $_SESSION['user'] = array_filter(array_map('array_filter', $_POST['user']));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!