title: Update table according to the selection box value in php
body: <p>I have a page in php that list the details of a person. What I need to do is that when I select a selection box value then the table should be updated corresponding to that selection box value.</p>
  
  <p>At first time the details of first row should be printed. When I select the approve leave/reject leave then table should be updated.</p>
  
  <pre><code>$query2 = "SELECT * FROM `leavetable` WHERE forwardedtoteacher=1";
  $result2 = mysql_query($query2);
  $numresults2= mysql_num_rows($result2);
  
      for ($i = 0; $i &lt; $numresults2; $i++)
      {
  
          $row2 = mysql_fetch_array($result2);
          $username = $row2['username'];
          $sdate = $row2['fromdate'];
          $edate = $row2['enddate'];
          $session = $row2['session'];
          $reason = $row2['reason'];
          $
  
          $query = "SELECT * FROM `user` WHERE username='$username'";
          $result = mysql_query($query);
          $numresults = mysql_num_rows($result);
          $row = mysql_fetch_array($result);
          $usern = $row['username'];
          $fname = $row['fname'];
          $lname = $row['lname'];
          $designation = $row['designation'];
          $phonenumber = $row['phonenumber'];
  
  
          echo'&lt;table&gt;&lt;tr&gt;&lt;td&gt;First name &lt;/td&gt;&lt;td style="padding-left:20px;"&gt;'.$fname.'&lt;/td&gt;&lt;/tr&gt;&lt;br&gt;';
  
          echo'&lt;tr&gt;&lt;td&gt;Last name &lt;/td&gt;&lt;td style="padding-left:20px;"&gt;'.$lname.'&lt;/td&gt;&lt;/tr&gt;&lt;br&gt;';
  
          echo'&lt;tr&gt;&lt;td&gt;Designation&lt;/td&gt;&lt;td style="padding-left:20px;"&gt;'.$designation.'&lt;/td&gt;&lt;/tr&gt;&lt;br&gt;';
  
          echo'&lt;tr&gt;&lt;td&gt;Phonenumber &lt;/td&gt;&lt;td style="padding-left:20px;"&gt;'.$phonenumber.'&lt;/td&gt;&lt;/tr&gt;&lt;br&gt;';
  
          echo'&lt;tr&gt;&lt;td&gt;Start Date &lt;/td&gt;&lt;td style="padding-left:20px;"&gt;'.$sdate.'&lt;/td&gt;&lt;/tr&gt;&lt;br&gt;';
  
          echo'&lt;tr&gt;&lt;td&gt;End Date &lt;/td&gt;&lt;td style="padding-left:20px;"&gt;'.$edate.'&lt;/td&gt;&lt;/tr&gt;&lt;br&gt;';
  
          echo'&lt;tr&gt;&lt;td&gt;Session  &lt;/td&gt;&lt;td style="padding-left:20px;"&gt;'.$session.'&lt;/td&gt;&lt;/tr&gt;&lt;br&gt;';
  
          echo'&lt;tr&gt;&lt;td&gt;Reason &lt;/td&gt;&lt;td style="padding-left:20px;"&gt;'.$reason.'&lt;/td&gt;&lt;/tr&gt;&lt;br&gt;';
  
          echo"&lt;/table&gt;\n";
          ?&gt;
          &lt;form action = &lt;?php echo $_SERVER['PHP_SELF']; ?&gt; method = 'POST'&gt;
  
          &lt;?php
          echo '&lt;select name="leavestatus"&gt;';
          echo '&lt;option value="Approve Leave"&gt;Approve Leave&lt;/option&gt;';
          echo '&lt;option value="Reject Leave"&gt;Reject Leave&lt;/option&gt;';
          echo '&lt;/select&gt;';
  
          if(isset($_POST['leavestatus']))
          {
          if($_POST['leavestatus'] == 'Approve Leave')
              {
  
                  $stmt = "UPDATE leavetable SET forwardedtohod = 1,forwardedtoteacher = 0 WHERE username = '$usern'";
  
                  $stmt11 = mysql_query($stmt);
  
              }
          if($_POST['leavestatus'] == 'Reject Leave')
              {
  
  
                  $stmt2 = "UPDATE leavetable SET fromdate = '',enddate ='',session = '',typeofleave = '',forwardedtoteacher=0,forwardedtohod=0 WHERE username= '$usern'";
  
                  $stmt3 = mysql_query($stmt2); 
  
              }
  
  
        }
  
          print "&lt;hr&gt;";
  
  
  
      }
  </code></pre>
  
  <p>Here. I have two tables,leavetable and user table. What I did is,I fetched details from these tables and displayed. Then I provided a checkbox to each row and When I select the Approve Leave corresponding code should work and when reject leave is selected the corresponding code should work. That is I need to update the table with selection box value. Thanks in advance</p>
  
  <p>Fisrt name : <br>
  Last name  : <br>
  Designation : <br>
  ..... <br>
  ..... <br>
  ..... <br></p>
  
  <p>|Approve Leave |v|  ------> Selectionbox<br></p>
  
  <p>-----------------------------------------------------<br></p>
  
  <p>Fisrt name : <br>
  Last name  : <br>
  Designation : <br>
  ..... <br>
  ..... <br>
  ..... <br></p>
  
  <p>|Approve Leave|  ------> Selectionbox <br></p>