doushishi6513 2018-02-09 09:26
浏览 21
已采纳

如何在PHP中使用变量的新值?

Why does $validSave always contains FALSE even I click the btnEdit?

Here's the code:

$validSave = false;

if(isset($_POST['btnSearch'])){
   if(isset($_POST['btnEdit']){
     $validSave = true;
   }
}

if(isset($_POST['btnSave']){
     if($validSave){
         ... //Does not go here after I press the btnEdit
     }
     else{
        echo "Unable to save"; //It always goes here
     }
}
  • 写回答

1条回答 默认 最新

  • doufuhuang6981 2018-02-09 09:37
    关注

    $validSave always contains FALSE because if(isset($_POST['btnSearch'])) and if(isset($_POST['btnEdit']) are false.if one condition is true and one condition is false then state will not change of $validSave if you have two button if(isset($_POST['btnSearch'])) and if(isset($_POST['btnEdit']) try to use like this

    if(isset($_POST['btnSearch']) || isset($_POST['btnEdit'])){
      $validSave = true;
    }
    

    or if you have one button and one field you need to try like that

    if(isset($_POST['your button name'])){
       $otherField=$_POST['btnSearch'];
        $validSave = true;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件
  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了
  • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
  • ¥188 需要修改一个工具,懂得汇编的人来。
  • ¥15 livecharts wpf piechart 属性
  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题