用户点击时PHP提交按钮

I will like to get multiple request after clicking submit. Meaning that after i clicked submit and get the result, i will like to inquire results again and click submit again. I don't want to lead myself back to nothingness.

 <?php
 error_reporting(0);
 if (!$_POST['submit'])
 {
 <form action="http://localhost/test.php" method="post">
 Type of Leave: 
 <select name="leave">
 <option value=""selected="selected"></option>
 <option VALUE="Medical Leave"> Medical Leave</option>
 <option VALUE="Unpaid Leave"> Unpaid Leave</option> 
 </select>
 <input type="submit" name="submit" value="Check!" />
 </form>
 <?php
 }
 else
 {
 $conn=odbc_connect("employee","","") or die (odbc_errormsg());
 if (!$conn)  
 {
 exit
 ("Connection Failed: " . $conn);
 }
 else
 {
 $choice = $_POST['leave'];
 $sql="SELECT * FROM balance WHERE ID=$username";
 $rs=odbc_exec($conn,$sql);
 ?>
 <?php
 while (odbc_fetch_row($rs))
 {
 $choice=odbc_result($rs,"$choice");
 echo "<tr><td>$choice</td>";
 }
 odbc_close($conn);
 echo "</table>";
 }
 }

Currently the code itself queries out the expected output that I want, but the only downside is it stays there as an output. What my aim is to have the submit and the select choice option stays there so that I can continue to output the result I want, thanks.

The best user experience would be to use AJAX to dynamically change the results table depending on what is chosen in the dropdown. For a simpler solution, you could try moving the form up and out of the if/else loop. Put the form first, then after the form prints, check for if ($_POST['submit']).

In this example, I also added a little function to add selected="selected" to whichever option was chosen for this submit. It's very rough, but you get the idea.

<?php
function matchPost($name,$val) {
if($val == $name)
    echo 'selected="selected"';
}
?>

<form action="http://localhost/test.php" method="post">
 Type of Leave: 
 <select name="leave">
 <option value=""></option>
 <option <?php matchPost('Medical_Leave',$_POST['leave']); ?> VALUE="Medical_Leave"> Medical Leave</option>
 <option <?php matchPost('Unpaid_Leave',$_POST['leave']); ?> VALUE="Unpaid_Leave"> Unpaid Leave</option> 
 </select>
 <input type="submit" name="submit" value="Check!" />
 </form>

<?php
 if ($_POST['submit'])

 {
 $conn=odbc_connect("employee","","") or die (odbc_errormsg());
 if (!$conn)  
 {
 exit
 ("Connection Failed: " . $conn);
 }
 else
 {
 $choice = $_POST['leave'];
 $sql="SELECT * FROM balance WHERE ID=$username";
 $rs=odbc_exec($conn,$sql);
 ?>
 <?php
 while (odbc_fetch_row($rs))
 {
 $choice=odbc_result($rs,"$choice");
 echo "<tr><td>$choice</td>";
 }
 odbc_close($conn);
 echo "</table>";
 }
 }