The script below is designed to verify user logins. It takes the user input from a form and checks that the username and password are valid. If they are not the form, (show_login.html) is reloaded. When this occurrs I would like an error message to be displayed on the form, like "bad login try again" etc. I have tried all sorts to do this but can't get anywhere, does anybody know any code I can insert into the script below to add an error message when the form is reloaded?
Any help would be much appreciated.
<?
if ((!$POST[username]) || (!$POST[password])) {
header("Location: http://127.0.0.1/show_login.html");
exit;
}
$db_name = "test";
$table_name = "user";
$connection = @mysql_connect("*****", "", "*****")
or die(mysql_error());
$db = @mysql_select_db($db_name, $connection) or die(mysql_error());
$sql = "SELECT * FROM $table_name WHERE username = '$_POST[username]' AND password = password('$_POST[password]')";
$result = @mysql_query($sql,$connection) or die(mysql_error());
$num = mysql_num_rows($result);
if ($num != 0) {
$msg = "<P><b>Welcome:</b><i> <u>$_POST[username]</u></i></P>";
} else {
header("Location: http://127.0.0.1/show_login.html");
exit;
}
?>
<HTML>
<HEAD>
<TITLE>welcome</TITLE>
</HEAD>
<BODY>
<? echo "$msg"; ?>
</BODY>
</HTML>