如何将禁用的复选框值发送到数据库

时间:2019-04-10 09:34:08

标签: html mysqli

我想将禁用复选框的值发送到数据库中。我试图将其设置为只读,但允许用户选中/取消选中该字段。

<?php
  if(isset($_POST['bookbtn'])){

    if(!empty($_POST['checky'])) {

      $lang = implode(",",$_POST['checky']);

      // Insert and Update record
      $checkEntries = mysqli_query($conn,"SELECT * FROM seats");
     if($test == $hotel)
         $ic = "update seats set seat='$lang'  where hotelname='$test' ";
        mysqli_query($conn,$ic); 

         }else{
        $del = "insert into seats (hotelname,seat) values ('$test','$lang')";
         mysqli_query($conn,$del);
      } 
    }

  // code for checkbox
  <form method="post">
        <div><input type="submit"class="button1" name="bookbtn" value="Book Your table" onclick="bookbtn()"/>
        <input type="reset" class="button1"name="resetboxes"value="Reset"></div><br><br><div id="mask2"style="float:left;width:20%;">

<?php $i=1;
    while ($i<=$tab) 
   {?>
    <div class="TWO">
        <div class="check"style="height:40px;width:120px;">
            <div class="seconda">
            </div>
            <div class="secondb">
            <input type ="checkbox"name="checky[]"id="<?php echo "two".$i;?>"class="tabtwo"style="width:30px;height:30px;"
            value="<?php echo "two".$i;?>"
            <?php if (in_array("two".$i, $expcheck)) {?>
               checked="checked"<?php }else {echo "none";}?>disabled>
    </div>

            <div class="secondc">
            </div>
        </div>
    </div>
 <?php 
 $i++;
}
?>

1 个答案:

答案 0 :(得分:1)

尝试

<input type="checkbox" onclick="this.checked=this.defaultChecked" />
<input type="checkbox" checked onclick="this.checked=this.defaultChecked" />