The dropbox will list colors, the radio buttons will list foods.It also will ask for First and Last Name.
I have worked on it for a while and this is my problem. I created a HTML/PHP Form that lists the drop box and radio button.Here is my Form page:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Form</title>
</head>
<body>
<form action="PAGE08.php" method="post">
<h3> Please enter your full Name and choose your favorite color and type of food</h3>
<table>
<tr>
<td> FirstName: </td>
<td><input type="text" name="FirstName" /></td>
</tr>
<tr>
<td>LastName: </td>
<td><input type="text" name="LastName" /></td>
</tr>
</table>
<div><h3> Choose your favorit color </h3></div>
<?php
$color["Rose"]="Red";
$color["Viola"]="Blue";
$color["Pine"]="Green";
$color["Poppy"]="Cyan";
$color["Lilie"]="Magenta";
$color["Daffodil"]="Yellow";
?>
<tr>
<td><select name = "color" id = "color"></td>
</tr>
<?php
foreach ($color as $flower => $favorite )
{
echo "<option value=\"$favorite\"> $favorite </option> \n";
}
?>
</select>
<br/><br/>
<div><h3> Choose your favorite food</h3></div>
<?php
$food["ribs"]="Barbeque";
$food["lowmain"]="Chinese";
$food["habatchi"]="Japanese";
$food["padthai"]="Thai";
$food["texas"]="Steak";
$food["veggy"]="Vegan";
$food["taco"]="Mexican";
foreach ($food as $menue => $fav )
{
echo "<input type=\"radio\" name=\"radioOption\"value=\"fav\"> $fav <br/>";
}
?>
<tr>
<td><input type="submit" name="button" value="Submit"/></td>
</tr>
</form>
</body>
</html>
When I click submit it gives me following error messages:
Notice: Undefined index: food in G:\xampp\htdocs\classphp\CISP1720osimonsLab008_PAGE.php on line 17
It also does not print out the selected radio button item. I does print First, Last name and color.
Here is my code for the return action page:
<!DOCTYPE HTML>
<?php
$FirstName= $_POST["FirstName"];
$FirstName = trim($_POST['FirstName']);
$LastName = $_POST["LastName"];
$LastName = trim($_POST['LastName']);
$color = ($_POST["color"]);
$food = ($_POST["food"]);
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Page</title>
<?php
$LastName = ucfirst(strtolower($LastName));
$FirstName = ucfirst (strtolower($FirstName));
if(empty($FirstName) || empty($LastName))
{
echo "<p><b>Incorrect Input</b></p>\n";
echo "<p> You mist a Field. Please enter your full Name</p>\n";
}
else if (is_numeric($FirstName)|| is_numeric($LastName))
echo "<p><b>Incorrect Input</b></p>\n";
echo "<p>You entred a numeric values</p>\n";
}
else if (strlen($FirstName) > 20 || strlen($LastName) > 20 )
{
echo "<p><b>Incorrect Input</b></p>\n";
echo "<p>First or last Name is too long.</p>\n";
echo "<p><i>You can only use up to 20 charachters</i></p>";
}
else
{
echo "<p> First Name: $FirstName </p>\n";
echo "<p> Last Name: $LastName </p>\n";
echo "Your Favorit color is: ";
print_r($color);
echo "<br/>";
echo "Your Favorit food is: " ;
print_r($food);
}
?>
</body>
</html>
I would love to know where I am going wrong.

New Topic/Question
Reply



MultiQuote





|