我没有运行(提交)表格

时间:2017-12-02 15:02:25

标签: php

我没有运行查询2(提交)表单。 只需刷新页面即可。 我如何解决这个功能“diе();”

            <?php
            if (isset($_POST['query1'])) {
//working.. next
            ?>
            <?php
            if (isset($_POST['query2'])) {
            die("Go die"); //not working, how to fix?
            }
            ?>
            <form method="post">
                ...Query2 (not working)
                <p><input type="submit" value="Query2" name="query2"></p>
            </form>
            <?php
            }
            ?>
            <form method="post">
                ...Query1 (working)
                <p><input type="submit" value="Query1" name="query1"></p>

1 个答案:

答案 0 :(得分:0)

query2条件位于query1条件内,因此永远不会使用您当前的代码执行(因为处理query1时未设置query2)。它需要移到外面,或者您需要更新form,以便在query1中设置form2。所以:

<?php
if (isset($_POST['query1'])) {
     //working.. next
     if (isset($_POST['query2'])) {
          die("Go die"); //not working, how to fix?
     }
?>
<form method="post">
    ...Query2 (not working)
    <p><input type="submit" value="Query2" name="query2"></p>
    <input type="hidden" value="just so we are set" name="query1">
</form>
<?php
}
?>

(上述方法假定每次都应执行query1代码)或

<?php
if (isset($_POST['query1'])) {
     //working.. next
}
if (isset($_POST['query2'])) {
          die("Go die"); //not working, how to fix?
}
if (isset($_POST['query1'])) {
?>
<form method="post">
    ...Query2 (not working)
    <p><input type="submit" value="Query2" name="query2"></p>
    <input type="hidden" value="just so we are set" name="query1">
</form>
<?php
}
?>