Page 1 of 1

undefined variables?

Posted: Wed Apr 23, 2003 10:23 am
by wallabee
I think most people who check this thread out are going to dismiss it as a $_POST or $_GET problem, but it doesn't seem to be. I've just started working with headers and footers, and keep nabbing the same error:

"Notice: Undefined index: Message in C:\Inetpub\armcircles\htdocs\ben\php\final\login.php on line 4"

The code for the login.php:

Code: Select all

<?php
$PageTitle = "Login Page";
require("header.php");
if ($_GET['Message'] == "Invalid"){
		print("<B><CENTER><FONT COLOR= RED>Login Error:</B> The username and password you entered does not match what is on file.  Please try again!</FONT></CENTER>\n");
}
print("<FORM ACTION="HandleLogin.php" METHOD=POST>\n");
print("Username: <INPUT TYPE=TEXT NAME=UserName><BR>\n");
print("Password: <INPUT TYPE=PASSWORD NAME=Password><BR>\n");
print("<INPUT TYPE=SUBMIT NAME=SUBMIT VALUE="Submit">\n");
require("footer.php");
?>

A bit on the code: Basically it's a login script. HandleLogin.php basically just takes the user input and checks to see if it's a valid username and password. If it is, it tosses the user to index.php. If not, it returns them back to login.php with $message = invalid.

the basic idea, which isn't too complex, is that if login.php loads up and $message = invalid, then i want the error message to display. this works quite well. my problem is when there ISN'T a $message in existance, PHP still errors out, even though I just want it to "ignore" the if statement if there isn't a $message. does anyone know the reason behind this? is it a server setting? thanks for any help you can give me.

Posted: Wed Apr 23, 2003 10:31 am
by volka
it's "only" a warning not an error. Your php probably is configured to add errors/warnings to the output stream.
It complains about accessing an index that is not within $_GET. You can test the existence of a variable or an index via isset(...)