lundi 20 mai 2019

Database stores the starting checkbox value

hey i have some problems in my code, when i am storing data through checkbox it stores data but there there is a little bit problem Here is my full code :

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

if(isset($_POST['save'])){

  $contact_sms = $_POST['contact_sms'];  
  $check[] = $_POST['check'];
  $firm_name = $_POST['firm_name'];
  var_dump($_POST);
  $checkbox = $_POST['check'];

  for($i=0;$i<count($checkbox);$i++){
    $bulksms="INSERT INTO bulk_sms (sent_sms,firmname_sms,contact_sms) VALUES('".$checkbox[$i]. "','".$firm_name[$i]. "','$contact_sms')";
    $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">   
      <?php
        $i=0;
        while($row=mysqli_fetch_assoc($query)){
        $id = $row['id'];
        $firm_name = $row['firm_name'];
      ?>  

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

      <?php
        $i++;
        }
      ?>

      <input type="text" class="form-control" name="contact_sms" placeholder="Contact Number.."> 
      <button type="submit" class="btn btn-success" name="save">Send</button>
    </form>

When i mark any checkbox and submit it, id of checked box is stored correctly inside the sent_sms field but the firm_name is stored from starting inside firmname_sms field i.e. inside firmname_sms field, checked value is not storing.

Is it possible with foreach loop ? If yes, please help me out......




Aucun commentaire:

Enregistrer un commentaire