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']));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 socket通信实现多人聊天室疑惑
  • ¥15 DEV-C++编译缺失
  • ¥33 找熟练码农写段Pyhthon程序
  • ¥100 怎么让数据库字段自动更新
  • ¥15 antv g6 力导向图布局
  • ¥15 quartz框架,No record found for selection of Trigger with key
  • ¥15 锅炉建模+优化算法,遗传算法优化锅炉燃烧模型,ls-svm会搞,后面的智能算法不会
  • ¥20 MATLAB多目标优化问题求解
  • ¥15 windows2003服务器按你VPN教程设置后,本地win10如何连接?
  • ¥15 求一阶微分方程的幂级数