<?
$val="";
if(isset($_POST['save']))
{
if(isset($_POST['color']))
{
$color=$_POST['color'];
foreach($color as $val)
{
echo $val."<br>";
}
}
}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form method="post">
<input type="checkbox" name="color[]" value="blue" <? if($val=='blue'){ echo "checked"; }?> />Blue
<input type="checkbox" name="color[]" value="red"<? if($val=='red'){ echo "checked"; }?> />Red
<input type="checkbox" name="color[]" value="green"<? if($val=='green'){ echo "checked"; }?>/>Green
<input type="checkbox" name="color[]" value="yellow"<? if($val=='yellow'){ echo "checked"; }?>/>Yellow
<input type="checkbox" name="color[]" value="white"<? if($val=='white'){ echo "checked"; }?>/>White
<input type="submit" name="save">
</form>
</body>
</html>
When I select one checkbox, then I click "save", the check box is checked and the colour is visible on top.
But, when I select more than one check box, then I click "save", only one checkbox is checked, but the colours are visible on the top.
So I need my code to keep the checkbox checked and have the colours remain the same. E.g. When I select red, green, yellow check box, after I click "save", it should be "CHECKED".