<html>
<head>
<title></title>
</head>
<body>

<?php

error_reporting
(E_ALL);

$names=array("Tom","Fred","Harry","George","Justin","Percival","Montmorency");
?>

<form method="post" action="">
<table>
<?php
for($i=0;$i<count($names);$i++){
print
"<tr><td>".$names[$i]."</td><td><input type='checkbox' name='name_selector[]' value='$names[$i]'></td></tr>";
}
?>
<tr><td>&nbsp;</td><td>&nbsp;</td>
<tr><td><input type="submit" name="submit" value="Submit"></td><td></td>
</table>

<?php
if(isset($_POST['name_selector'])){
print
"You have selected... <ul>";
    for(
$i=0;$i<count($_POST['name_selector']);$i++){
    print
"<li>".$_POST['name_selector'][$i]."</li>\n";
    print
"<input type='hidden' name='name_selector[]'value='".$_POST['name_selector'][$i]."'>\n";
    }
print
"</ul>";

}

//Exercise 1
//Modify the code to give an error message if
//nothing is selected.

//Exercise 2
//Modify the code to maintain the choices
//so that they do not disappear when the form is submitted

?>
</form>
</body>
</html>