Whats wrong with my php form?

Soldato
Joined
7 Jan 2007
Posts
10,607
Location
Sussex, UK
Hi, I can't work out why it wont work.. can anyone shed any light?

PHP:
<?php
$education = $_POST["education"];

if (!isset($_POST['submit'])) { // if page is not submitted to itself echo the form
?>
<html>
<head>
<title>Personal INFO</title>
</head>
<body>
<form method="post" action="<?php echo $PHP_SELF;?>">
Select a Level of Education:<br />
<select name="education">
<option value="Jr.High">Jr.High</option>
<option value="HighSchool">HighSchool</option>
<option value="College">College</option></select><br />
<input type="submit" value="submit" name="submit">
</form>
<?php
elseif  ($education == "Jr.High") {
		echo "$education."! . "Elseif for Junior High has worked!""<br />";
		}
		
elseif  ($education == "HighSchool") {
		echo "$education."! . "Elseif for HighSchool has worked!""<br />";
		}

elseif  ($education == "College") {
		echo "$education."! . "Elseif for College has worked!""<br />";
		}	
		
else {
		echo "There has been an error! You suck at this!";

?>



</body>
</html>
 
My code now looks like this:

PHP:
<?php
$education = $_POST["education"];

if (!isset($_POST['submit'])) { // if page is not submitted to itself echo the form

<html>
<head>
<title>Personal INFO</title>
</head>
<body>
<form method="post" action="<?php echo $PHP_SELF;?>">
Select a Level of Education:<br />
<select name="education">
<option value="Jr.High">Jr.High</option>
<option value="HighSchool">HighSchool</option>
<option value="College">College</option></select><br />
<input type="submit" value="submit" name="submit">
</form>

elseif  ($education == "Jr.High") {
		echo $education . ' Elseif for Junior High has worked!<br />';
		}
		
elseif  ($education == "HighSchool") {
		echo $education . ' Elseif for HighSchool has worked!<br />';
		}

elseif  ($education == "College") {
		echo $education . ' Elseif for College has worked!<br />';
		}	
		
else {
		echo "There has been an error! You suck at this!";
		}

?>



</body>
</html>

Unfortunately, still getting:

HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request.
 
ok my mamp is playing up. But I now get this error on my webhosting:


Parse error: syntax error, unexpected $end in /home/deanbeam/public_html/dropmenu.php on line 34

PHP:
<?php
$education = $_POST["education"];

if (!isset($_POST['submit'])) { // if page is not submitted to itself echo the form
?>
<html>
<head>
<title>Personal INFO</title>
</head>
<body>
<form method="post" action="<?php echo $PHP_SELF;?>">
Select a Level of Education:<br />
<select name="education">
<option value="Jr.High">Jr.High</option>
<option value="HighSchool">HighSchool</option>
<option value="College">College</option></select><br />
<input type="submit" value="submit" name="submit">
</form>
<?php
echo "Traveling to $education<br />";
switch ($education){
	case "Jr.High":
		echo "Bring an extra $500";
		break;
	case "High School":
		echo "Bring an open mind";
		break;	
	case "College":
		echo "Bring 15 bottles of SPF 50 Sunscreen";
		break;	
	
}

?>
 
Ok now not producing a parse error, just not working as intended:p

When I now click submit it now says cannot find url.... :p Why isn't going through the if and elseif statements?

PHP:
<?php 
$education = $_POST["education"]; 

if (!isset($_POST['submit'])) {
		echo <<< EOT

<html> 
<head> 
<title>Personal INFO</title> 
</head> 
<body> 
<form method="post" action="<?php echo $PHP_SELF;?>"> 
Select a Level of Education:<br /> 
<select name="education"> 
<option value="Jr.High">Jr.High</option> 
<option value="HighSchool">HighSchool</option> 
<option value="College">College</option></select><br /> 
<input type="submit" value="submit" name="submit"> 
</form>
EOT;

}

if  ($education == "Jr.High") { 
        echo $education . ' Elseif for Junior High has worked!<br />'; 
        } 
         
elseif  ($education == "HighSchool") { 
        echo $education . ' Elseif for HighSchool has worked!<br />'; 
        } 

elseif  ($education == "College") { 
        echo $education . ' Elseif for College has worked!<br />'; 
        }     
         

?> 



</body> 
</html>
 
Working!

It was the form action line that was bad before.

PHP:
<?php 
$education = $_POST["education"]; 

?>


<html> 
<head> 
<title>Personal INFO</title> 
</head> 
<body> 
<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
Select a Level of Education:<br /> 
<select name="education"> 
<option value="Jr.High">Jr.High</option> 
<option value="HighSchool">HighSchool</option> 
<option value="College">College</option></select><br /> 
<input type="submit" value="submit" name="submit"> 
</form>

<?php


if  ($education == "Jr.High") { 
        echo $education . ' Elseif for Junior High has worked!<br />'; 
        } 
         
elseif  ($education == "HighSchool") { 
        echo $education . ' Elseif for HighSchool has worked!<br />'; 
        } 

elseif  ($education == "College") { 
        echo $education . ' Elseif for College has worked!<br />'; 
        }     
         

?> 



</body> 
</html>
 
Back
Top Bottom