Hey all. I've just started reading PHP and MySQL, for Dynamic Web Sites (fourth edition) I've a problem in regards for solving a pursue goal. It is in Chapter 2, and goes like so:
Create a form that contains a select
menu or series of check boxes that
allow for multiple sections. Then, in
the handling PHP script, display the
selected items along with a count of
how many the user selected. I would like to have it all on one page. So I'm doing something like this
<?php if($_SERVER["REQUEST_METHOD"] == "POST"){
$formdata = $_POST['interests'];
foreach($formdata as $interests => $values){
echo $values . " ";
}
$result = $values;
echo "You have checked " . count($formdata) . " boxes " .
"The boxes were " . $result;
}
?>
<form method="POST" action="own_excercises.php">
<input type="checkbox" name="interests[]" value="music" /> Music
<input type="checkbox" name="interests[]" value="movies" /> Movies
<input type="checkbox" name="interests[]" value="books" /> Books
<input type="checkbox" name="interests[]" value="games" /> Games
<input type="submit" name="sumbit" value="submit" />
</form>
This is what I've come up with this far. I can count the checkboxes check, and in the foreach echo the values of the checkboxes selected, but I can seem to get the values from the foreach in my $result variable. It only display 1 value of the first selected checkbox. I figure I just need a little push in the right direction. If possible it would help a lot to see a different solution to this problem. There are just so many ways to solve the same problem. Thanks a bunch! // Archaic