Submitting form data to script in same php document
Posted: Mon Aug 31, 2009 4:24 pm
I'm having difficulty passing form data to a script in the same document. When I run the document through a browser from my localhost server, it doesn't iterate through the 'if' statement and just drops through to the 'else' section. Can someone help me find the needle in this small hay stack. Thanks for any help.
I have the following small php document called Education.php:
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Educational Achievements</title>
<meta http-equiv="content-type"
content="text/html; charset=iso-8859-1" />
</head>
<body>
<h1>Educational Achievements</h1><hr />
<?php
function checkEducation($Level) {
global $education;
if (isset($education)) {
$FindLevel = implode(",", $education);
if (strpos($FindLevel, $Level) !== FALSE)
return " selected = 'selected'";
}
return "";
}
if (isset($education)) {
echo "<p>You selected the following:</p>";
foreach ($education as $degree) {
echo "$degree<br />";
}
}
else
echo "<p>Select all your education achievements. (Hold your Ctrl key to select multiple items.)</p>";
?>
<form action="Education.php" method="get" enctype="application/x-www-form-urlencoded">
<p><select name="education[]" multiple="multiple" size="8">
<option value="High School Diploma" <?= checkEducation("High School Diploma"); ?> >High School Diploma</option>
<option value="Associate's Degree" <?= checkEducation("Associate's Degree"); ?> >Associate's Degree</option>
<option value="Bachelor's Degree" <?= checkEducation("Bachelor's Degree"); ?> >Bachelor's Degree</option>
<option value="Master's Degree" <?= checkEducation("Master's Degree"); ?> >Master's Degree</option>
<option value="Doctorate Degree" <?= checkEducation("Doctorate Degree"); ?> >Doctorate Degree</option>
<option value="Undergraduate Certificate" <?= checkEducation("Undergraduate Certificate"); ?> >Undergraduate Certificate</option>
<option value="Postbaccalaureate Certificate" <?= checkEducation("Postbaccalaureate Certificate"); ?> >Postbaccalaureate Certificate</option>
</select></p>
<p><input type="submit" value="Submit Education" /></p>
</form><hr />
</body>
</html>
I have the following small php document called Education.php:
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Educational Achievements</title>
<meta http-equiv="content-type"
content="text/html; charset=iso-8859-1" />
</head>
<body>
<h1>Educational Achievements</h1><hr />
<?php
function checkEducation($Level) {
global $education;
if (isset($education)) {
$FindLevel = implode(",", $education);
if (strpos($FindLevel, $Level) !== FALSE)
return " selected = 'selected'";
}
return "";
}
if (isset($education)) {
echo "<p>You selected the following:</p>";
foreach ($education as $degree) {
echo "$degree<br />";
}
}
else
echo "<p>Select all your education achievements. (Hold your Ctrl key to select multiple items.)</p>";
?>
<form action="Education.php" method="get" enctype="application/x-www-form-urlencoded">
<p><select name="education[]" multiple="multiple" size="8">
<option value="High School Diploma" <?= checkEducation("High School Diploma"); ?> >High School Diploma</option>
<option value="Associate's Degree" <?= checkEducation("Associate's Degree"); ?> >Associate's Degree</option>
<option value="Bachelor's Degree" <?= checkEducation("Bachelor's Degree"); ?> >Bachelor's Degree</option>
<option value="Master's Degree" <?= checkEducation("Master's Degree"); ?> >Master's Degree</option>
<option value="Doctorate Degree" <?= checkEducation("Doctorate Degree"); ?> >Doctorate Degree</option>
<option value="Undergraduate Certificate" <?= checkEducation("Undergraduate Certificate"); ?> >Undergraduate Certificate</option>
<option value="Postbaccalaureate Certificate" <?= checkEducation("Postbaccalaureate Certificate"); ?> >Postbaccalaureate Certificate</option>
</select></p>
<p><input type="submit" value="Submit Education" /></p>
</form><hr />
</body>
</html>