I have added two checkboxes on page with submit button. After submitting there is a method having foreach loop to check which checkbox is checked , and that checkbox value should get in variable. If both checkbox's are checked then it should append both values in variable. But in my case the values are repeating. And also if i check both checkboxes it is picking up only second checkbox value.
Below is my code for HTML :
<form name="" action="" method="post">
<input type="checkbox" name="checkbox[]" value="Training"/> Training <br/><br/>
<input type="checkbox" name="checkbox[]" value="Posting"/> Posting<br/><br/>
<input type="submit" value="Submit"/>
</form>
Code for PHP:
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
$value = "";
$name = $_POST['checkbox'];
// optional
// echo "You chose the following color(s): <br>";
foreach ($name as $value){
//echo $value.", ";
$value .= $value;
}
echo $value;
//print "<script>alert('".$value."')</script>";
}
?>