PHP Notice: Undefned Variable Issue?

Stjerne

New member
Hi, everyone. I'm quite new to PHP, and I keep received the 'Notice: Undefined variable' notice and I want to know how to fix it without taking off the error reporting from the php.ini file. Is there a way to correct this notice so it doesn't show anymore without altering the php.ini file?

My code is quite simple, here it is (Don't mind the blank username/passwords and other necessary places):

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>
<title></title>
<meta name="keywords" content="">
<?php
mysql_connect("localhost" , "" , "") or die(mysql_error());
mysql_select_db("") or die(mysql_error());

if (isset($_POST['Submit'])){
$UserName = $_POST['Name'];
}

else {
$_SERVER['PHP_SELF'];
}
?>
</head>

<body>

<form action="<?php $_SERVER['PHP_SELF']; ?>" method="POST">
Name: <input type="text" name="Name" />
<input type="submit" name="Submit" value="Submit Sentence" />
</form><br />
<?php
echo $UserName;
?>

</body>

</html>

I don't understand why it continues to say the variable is 'undefined' if I've just defined it with the $_POST. Can someone help me fix this?

Thanks!
 
Back
Top