dongxie8906 2013-04-26 19: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-26 20: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']));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部