Thursday, January 21, 2016

PHP Arrays: How To Save an Array in PHP from Checkbox

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());
}
?>



PHP Arrays: How To Save an Array in PHP from Checkbox

PHP Arrays: How To Save an Array in PHP from Checkbox Rating: 4.5 Diposkan Oleh: Emoblazz

0 comments:

Post a Comment