undefined php variable on page load

Soldato
Joined
7 Jan 2007
Posts
10,607
Location
Sussex, UK
Last problem I have is that when I load my formpage.php it errors with undefined variable in the for each of the cases in the switch.

I suspect it's something to do wtih the isset submit stuff at the top, because until someone presses submit, then the variable $education is not defined.. but I am unsure how to fix it... Can anyone help me?

PHP:
<?php
if (isset($_POST['submit'])) {
  if (isset($_POST["Education"])){
	$education = $_POST["Education"];
	}
}

?>

<html> 
<head> 
<title>Personal INFO</title> 
</head> 
<body> 
<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
Select your level of education:<br /> 
<select name="Education"> 
<option value="Default"></option> 
<option value="PrimarySchool">Primary School</option> 
<option value="MiddleSchool">Middle School</option> 
<option value="HighSchool">High School</option></select><br /> 
<input type="submit" value="submit" name="submit"> 
</form>

<?php

switch ($education){
	case "Default":
		echo "Display stuff";
		break;
    case "PrimarySchool":
		echo "Primary School";
		break;
    case "MiddleSchool":
        echo "Middle School";
        break;    
    case "HighSchool":
        echo "High School";
        break;   
        }

?> 

</body> 
</html>
 
ah yes, that works, i tried that on my mamp, but it came up with an undefined index error, just shoved the same file on my web hosting and no error.

I must have some super sensitive error reporting on my mamp.

am I ok to ignore?
 
Back
Top Bottom