This is too long for a comment at this point and have already outlined what you need to do in comments.
N.B.: I pulled this from a "now deleted" question as I was going to make a reference to it.
Note that if you're wanting to use the same name attribute for each checkbox, that you need to treat them as arrays using []
for all of them.
I.e.: name="the_name[]"
Base yourself on the following:
<?php
if(isset($_POST['test'])){
$a_counts = array();
foreach($_POST['test'] as $key => $val){
if(!isset($a_counts[$val])){
$a_counts[$val] = 1;
}else{
$a_counts[$val]++;
}
echo $key." => ".$val."<br>";
}
print_r($a_counts);
}
?>
<form action="" method="POST">
<input type="checkbox" name="test[]" value="red">
<input type="checkbox" name="test[]" value="green">
<input type="checkbox" name="test[]" value="yellow">
<input type="checkbox" name="test[]" value="blue">
<input type="submit" value="ok">
</form>
Or something like this which would be the better solution:
<form method="post">
<label class="heading">Select from the following:</label>
<input type="checkbox" name="check_list[]" value="Value 1"><label>Value 1</label>
<input type="checkbox" name="check_list[]" value="Value 2"><label>Value 2</label>
<input type="checkbox" name="check_list[]" value="Value 3"><label>Value 3</label>
<input type="checkbox" name="check_list[]" value="Value 4"><label>Value 4</label>
<input type="checkbox" name="check_list[]" value="Value 5"><label>Value 5</label>
<input type="submit" name="submit" Value="Submit"/>
</form>
<?php
if (isset($_POST['submit'])) {
if (!empty($_POST['check_list'])) {
// Counting number of checked checkboxes.
$checked_count = count($_POST['check_list']);
echo "You have selected following ".$checked_count." option(s): <br/>";
// Loop to store and display values of individual checked checkbox.
foreach ($_POST['check_list'] as $selected) {
echo "<p>".$selected ."</p>";
}
}
else {
echo "<b>Please Select at least One Option.</b>";
}
}
?>
<?php
if (!empty($_POST['check_list'])) {
// Counting number of checked checkboxes.
$checked_count = count($_POST['check_list']);
echo "You have selected following ".$checked_count." option(s): <br/>";
// Loop to store and display values of individual checked checkbox.
foreach ($_POST['check_list'] as $selected) {
echo "<p>".$selected ."</p>";
}
}
else {
echo "<b>Please Select at least One Option.</b>";
}
` not in pure PHP anyway. You need to name the inputs with different values.
– Funk Forty Niner May 04 '16 at 16:21