There will be cases wherein you are going to get values from checkboxes with same name and save it in different rows in your table. Below is your HTML code with 5 checkboxes.
HTML Code
<form method="post">
<input type="checkbox" class="form-control" name="answer[]" value="A">
<input type="checkbox" class="form-control" name="answer[]" value="B">
<input type="checkbox" class="form-control" name="answer[]" value="C">
<input type="checkbox" class="form-control" name="answer[]" value="D">
<input type="checkbox" class="form-control" name="answer[]" value="E">
</form>
PHP Code
<?php
$answer=$_POST['answer'];
foreach($answer as $value)
{
mysqli_query($con,"INSERT INTO answer(letter) VALUES('$value')")or die(mysqli_error());
}
?>
0 comments:
Post a Comment