donglao4370 2018-01-17 16:32
浏览 136

PHP - if(isset($ _ POST ['button1'')){... if(isset($ _ POST ['button2']))..不工作?

I have this code:

   echo'<form method="POST" action="">';

    echo'Code:<input type="text" name="name">';
    echo'<input type="submit" name="save" value="Save">';

    echo'</form>';

if(isset($_POST['save'])){

    //something
    echo'<form method="POST" action="">';

    echo'Code:<input type="text" name="name">';
    echo'<input type="submit" name="delh" value="Delete">';

    echo'</form>';

    if(isset($_POST['delh'])){
        // Cant show this! :(
        echo "Deleted!";

    }
}

When i press "DELETE", the page reloads and the message "Deleted!" remains hidden.


This is a schedule. The idea is if someone presses the Save button but has already saved an hour it says "You have already saved an hour, do you want to cancel it?". When it clicks "Delete", the hour is deleted from the database.

In the case where the Save button is pressed, but the person has not saved an hour, the delete button is not displayed.

  • 写回答

2条回答 默认 最新

  • dtd58256 2018-01-17 16:36
    关注

    This line:

    echo "Deleted!";
    

    Can only be reached if both of these conditions are true:

    if(isset($_POST['save'])){
        //...
        if(isset($_POST['delh'])){
    

    But the form you're showing contains no element named save. The first condition is false, so the code inside that if block never runs. (It may have been true in a previous request, but not in the request you're making with this form.)

    You may have meant to separate those conditions?:

    if(isset($_POST['save'])){
        //...
    }
    
    if(isset($_POST['delh'])){
        //...
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真