problem with multidemensional arrays - 10/13/05 08:18 AM
I am currently working on a project from the book. It is a very simple form. However the script to handle the form simply isnt working and I cant figure it out. I swear I have checked and double checked my syntax over and over. I was hoping someone might be able to give it a peek and tell me where im messing up. Thanks in advance.
The Form
The script handling the form :
All I get is a blank page.
The Form
Code
<form action="handle_about.php" method="post"> <fieldset><legend>Enter your information in the form below </legend> <b>Name:</b> <input type="text" name ="name" size="20" maxlength="40" /> <b>Interests:</b> <input type="checkbox" name="interests[]" value="Music" /> Music <input type="checkbox" name="interests[]" value="Books" /> Books <input type="checkbox" name="interests[]" value="Skiing" /> Skiing <input type="checkbox" name="interests[]" value="Napping" /> Napping </fieldset> <div align="center"><input type="submit" name="submit" value="Submit Information" /></div> </form>
Code
<?php if (strlen($_POST['name']) > 0) { $name = stripslashes($_POST['name']); } else { // If no name was entered... $name = NULL; echo ' <b>You forgot to enter your name!</b>'; } //Check $interests[] if (isset($_POST['interests'])) { $ints = NULL; //New message to be used. foreach ($_POST['interests']) as $key => $value) { //loop through each. $ints .= "$value, "; } $ints = substr($ints, 0, -2); $interests = TRUE; } else { $interests = NULL; echo ' <b>You forgot to enter your interests!</b>'; } if ($name && $interests) { echo "Thank you, <b>{$_POST['name']}</b>. You entered interests as: <tt>$ints</tt>"; } ?>