如何创建要回显的内容的if语句

时间:2019-06-15 10:35:47

标签: php mysqli

我希望有一个输入可以更改数据库中的值,如果按下该按钮,我希望弹出另一个输入以能够将数据库中的值更改回来。

我用Google搜索了一堆。一无所获。曾尝试与同学们接触,但没有成功

<form method="POST">
  <input type="submit" name="aanvraag" id="input2" value="Taxi aanvragen" />
</form>
<?php
  if(isset($_POST['aanvraag'])){ 
      if (mysqli_query($conn, "UPDATE klant SET aanvraag='1' WHERE username='$uname'")) {                         
          echo "<input type='submit' name='annuleer' id='input2' value='Annuleer taxi'/>";
          echo "Uw aanvraag is verzonden";
      } else {
          echo "error =". mysqli_error($conn);
      }
  }    
  if(isset($_POST['annuleer'])){ 
      if (mysqli_query($conn, "UPDATE klant SET aanvraag='0' WHERE username='$uname'")) {
          echo "Uw Taxi is geanuleerd";
      } else {
          echo "error =". mysqli_error($conn);
      }

1 个答案:

答案 0 :(得分:0)

    <?php
    $showfirst=true;
    if(isset($_POST['annuleer'])){
        $showfirst=true;
    }
    if(isset($_POST['aanvraag'])){
        $showfirst=false;
    }




    ?>


<form action="" method="post"> 
    <?php 
    if($showfirst){
        ?>
        <input type="submit" name="aanvraag" id="input2" value="Taxi aanvragen"/>
        <?php
    }else{
    ?>
    <input type="submit" name="aanvraag" id="input1" value="Taxi aanvragen"/>
    <?php
        }
    ?>

</form>
<?php
    if(isset($_POST['aanvraag'])){ 
        if (mysqli_query($conn, "UPDATE klant SET aanvraag='1' WHERE username='$uname'")) {                         
        echo "<input type='submit' name='annuleer' id='input2' value='Annuleer taxi'/>";
        echo "Uw aanvraag is verzonden";
        } else {
            echo "error =". mysqli_error($conn);
        }
    }    
    if(isset($_POST['annuleer'])){ 
        if (mysqli_query($conn, "UPDATE klant SET aanvraag='0' WHERE username='$uname'")) {
            echo "Uw Taxi is geanuleerd";
        } else {
            echo "error =". mysqli_error($conn);
        }
    }