I am new to PHP and I have been using a teach yourself book and am completely stumped on one of the exersises. To keep this brief, I have copied the code as supplied in the exersise verbatum but I cannot get my program to work. The object of the exersise is to display a page where the User can tick boxes to indicate their lieisure activities. The page should then be redisplayed to allow the User to make changes. My program displays the page okay but when the Submit button is clicked to submit my selection the previously ticked boxes are redisplayed blank. Here is the code:-
function generate_checkboxes($name, $options, $default=array())
{
if (!is_array($default))
$default = array();
foreach($options as $value => $label) {
$html .= "<INPUT TYPE=CHECKBOX ";
if (in_array($value, $default))
$html .= "CHECKED ";
$html .= "NAME=\"{$name}[]\" VALUE=\"$value\">";
$html .= $label . "<br>";
}
return($html);
}
$options = array(“movies” => “Going to the movies”,
“music” => “Listening to music”,
“sport” => “Playing or watching sports”,
“travel” => “Traveling”);
$html = generate_checkboxes(“interests”, $options, $interests);
?>
Please Select your interests
<?php print $html;?>If it’s any help we use PHP version 5.4 here.
I hope somebody can help if only to restore me to sanity
Many Thanks
Keith