I have a simple form in PHP like below:
<div class="col-md-4 ip"><label>Select Class</label><br>
<?php
$ret=mysqli_query($con,"select * from class");
$cnt=1;
while ($row=mysqli_fetch_array($ret)) {
?>
<div class="form-check">
<input name="classname[]" class="form-check-input" type="checkbox" value="<?php echo $row['class_name'];?>" id="flexCheckDefault">
<label class="form-check-label" for="flexCheckDefault">
<?php echo $row['class_name'];?>
</label>
</div>
<?php }?>
</div>
Now I want the user selected checkboxes to get inserted in database in separate rows, so I did the following PHP code:
$classname=$_POST['classname'];
foreach ($classname as $pop ){
$ins_query="insert into study_material (`classname`) values ('$pop')";
}
Now here the issue is only the last selected checkbox value is getting inserted and others are not.
Aucun commentaire:
Enregistrer un commentaire