如何在数据库中插入循环复选框值

时间:2019-05-15 11:56:37

标签: database mysqli checkbox

嘿,我几乎已经完成了必须插入数据库的复选框值,但是有一点问题。

这是我的完整代码:

<?php 
include("config.php");

if(isset($_POST['save'])){ 
  $contact_sms = $_POST['contact_sms'];
  $mobileno = $_POST['mobileno'];
  $checkbox = $_POST['check'];
  for($i=0;$i<count($checkbox);$i++){
    $bulksms="INSERT INTO bulk_sms (sent_sms,contact_sms,mobileno) VALUES('".$checkbox[$i]. "', '$contact_sms', '$mobileno')";
    $smsquery=mysqli_query($conn, $bulksms);
  } 
}

$sql="SELECT * FROM inventory_details where status ='0' AND role='0' ORDER BY position ASC, role ASC, visiter DESC limit 0,100";  
$query=mysqli_query($conn, $sql);

?>

  <form method="post" action="" id="msform">  
    <div class="container">
      <div class="row invent_det cate_head">
        <div class="col-md-2 "><strong>ID</strong></div>
        <div class="col-md-6 "><strong>PRIMARY MOBILE NO.</strong></div>
        <div class="col-md-4 "><strong><input type="checkbox" id="checkAl"> Select </strong></div>
      </div>

      <?php
        $i=0;
        $today_date=date("Y-m-d H:i:s", time()); 
        while($row=mysqli_fetch_assoc($query)){
        $id = $row['id'];
        $firm_name = $row['firm_name'];
        $PrimaryMobile_no = $row['PrimaryMobile_no'];
      ?>

      <div class="row">
        <div class="col-md-2 inventory-data">
          <input type="text" class="form-control" name="id_sms" value="<?php echo $id;?>" disabled>
        </div>
        <div class="col-md-6 inventory-data">
          <input type="text" class="form-control" name="mobileno[]" value="<?php echo $PrimaryMobile_no;?>" disabled>
        </div>
        <div class="col-md-4 inventory-data"><input type="checkbox" id="checkItem" name="check[]" value="<?php echo $row["firm_name"]; ?>-<?php echo $row["PrimaryMobile_no"]; ?>">
        </div>
      </div>

      <?php 
        $i++;
        }
      ?>
      <div class="row">
        <div class="inventory-data">
          <input type="text" class="form-control" name="contact_sms" placeholder="Contact Number..">
        </div>
        <button type="submit" class="btn btn-success" name="save">Send</button>
      </div>
    </div>
  </form>

<script>
  $("#checkAl").click(function () {
  $('input:checkbox').not(this).prop('checked', this.checked);
  });
</script>

当我单击“发送”按钮时,其存储的值是

<input type="checkbox" id="checkItem" name="check[]" value="<?php echo $row["firm_name"]; ?>-<?php echo $row["PrimaryMobile_no"]; ?>">

在“ sent_sms”列中的数据库中,我也将数字存储在“ contact_sms”域中。到目前为止,一切正常。

现在的问题是,我正在尝试存储的值

<input type="text" class="form-control" name="mobileno[]" value="<?php echo $PrimaryMobile_no;?>" disabled>

在“ mobileno”列内的数据库中,但操作失败。

请帮助我,任何提示或建议都非常欢迎。 预先感谢。

0 个答案:

没有答案