Trying to insert multiple checkbox values in separate rows in MySQL table in PHP not working [duplicate]
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.
source https://stackoverflow.com/questions/69789067/trying-to-insert-multiple-checkbox-values-in-separate-rows-in-mysql-table-in-php
Comments
Post a Comment