i need a message displayed if login fails

i have some code that works to a point, but doesn’t quite do exactly what i am after.

when the user enters the incorrect details into my login form i need it to display a message saying sorry you are not authorised to view this page. at present i just get a white screen.

[php]<?

import_request_variables(‘p’);

if ((!$username) || (!$password)) {

//header("Location: ./show_login.html");

print("<HTML>");

print("<HEAD>");

print("<TITLE>Error</TITLE>");

print("</HEAD>");

print("<BODY>");

print("User name = $username password = $password n");

print("</BODY>");

print("</HTML>");



exit;

}

$db_name = “_db”;

$table_name = “tablename”;

$connection = @mysql_connect(“localhost”, “username”, “me”)

or die("Couldn't connect.");

$db = mysql_select_db($db_name, $connection)

or die("Couldn't select database.");

$sql = “SELECT * FROM $table_name WHERE username=”$username" AND password=password("$password")";

$result = mysql_query($sql)

    or die ("Can't execute query.");

$num=0;

$num = mysql_numrows($result);

if ($num != 0) {

header("Location:http://www.ilt.bridgwater.ac.uk/~staua/contactslist.php");
exit;

} else

{ $msg = "

Sorry, you’re Not authorized!

";
exit;

}

?>

Secret Area <? echo "$msg"; ?>

[/php]

please help

Andy

Not sure what part of the code you need help with but I’m gonna go out on a limb and say the exit; statement after you set $msg is probobly giving you problems.

Keith

OK we need to find out where the program is going wrong. Go to “The Occasional Tutorial” and find the Debugging one. I would suggest using the echo/print idea. Once we have a better idea where it is going wrong we can help you fix it.

Sponsor our Newsletter | Privacy Policy | Terms of Service