dongzhun8449 2019-05-06 04:53
浏览 223

选中复选框后如何更新数据库状态,即使页面刷新后仍然检查复选框?

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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
    • ¥15 基于卷积神经网络的声纹识别
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP