How can PHP handle and store multiple checkbox values from a form submission?
When handling multiple checkbox values from a form submission in PHP, you can use an array to store the selected values. This way, you can loop through the array to access each selected checkbox value individually. To do this, make sure the checkbox inputs in your form have the same name attribute with square brackets (e.g., name="checkbox[]").
// Assuming the form has checkboxes with the name "checkbox[]"
if(isset($_POST['checkbox'])) {
$selectedCheckboxes = $_POST['checkbox'];
foreach($selectedCheckboxes as $checkbox) {
// Process each selected checkbox value here
echo $checkbox . "<br>";
}
}
Related questions
-
var_dump _REQUEST _POST
-
PHP HTTP Error 500 contact form
-
Is using COUNT(id) in queries faster than using COUNT(*)? What about counting only specific columns?COUNT(id) COUNT(*) specific columns