I am working on Online Booking System right now. I am having difficulties on how to update status of the seat on the database after being selected by the user. Furthermore, after select the seat(checkbox), the seat still checked even if I refreshed the page. Thanks in advance.

   //HTML code
   <form class="seat" action="stepper.php" method="post">
      <table>
        <?php while ($rows=mysqli_fetch_array($result2)) { ?>
          <tr id="<?php echo $row['seat_id']; ?>">
            <td data-target="seat"><input type="checkbox" class="seats" name="seat[]" value="<?php $rows['seat']; ?>" id="seat" autocomplete="off"></td>
          </tr>
        <?php } ?>
      </table>
      <br><br>
      <input type="submit" name="choose" value="Submit" class="button" data-role="update" data-id="<?php echo $row['seat_id']; ?>">
   </form>

//PHP code to update status of seat in the database
<?php
include_once('server.php');
$query2  = "SELECT * FROM seats";
$result2 = mysqli_query($db, $query2);

if(gettype($_POST['seat'])=="array"){
  foreach($_POST['seat'] as $val){
    $seat = $val;
    $query2 = "UPDATE seats SET status = '0' where seat_id='".$row_id."'";
    $result2 = mysql_query($query2);
    if($result2 === false) {
      die(mysql_error());
    }
    echo "Status " .$row_id. " is updated. <br>";
    }
  }

This is my database table from PHPMyAdmin. If the user select the seat, the status will be changed to '0' after user successfully click to submit button

0 Answers