I don’t think my code was correct – but i still added the
[code=php]..
to make it clearer.
Simply, I am looking for a way to display unsuccesful message on the same page where user tries to login (if no match found in the database). similarly, a message to say login successful and load the next page.
Dear all,
I am writing php code to connect to mysql server, check the user login and password entered in a form with the details in the table. if the logins exist I would like the user to be directed to the next page. alternatively the user should remain on the original page and an error message is displayed.
my code is not working. I enter wrong and correct logins and remain on the same page – nothing happens.
the form in the original page:
<form name=”loginform” action=”userlogin.php” method=post>
the userlogin.php contains:
[code=php] <?php
if ((!$_POST[username]) || (!$_POST[password])){
header(“location: homepage.php”);
exit;
}
$conn = mysql_connect(“localhost”, “root”, “”)
or die(mysql_error());
mysql_select_db(mysql, $conn) or die(mysql_error());
$sql = “select em_name from employee WHERE em_login = ‘$POST[username]’ AND em_password = password(‘$_POST[password]’)”;
$result = mysql_query($sql,$conn) or die(mysql_error());
if (mysql_num_rows($result) == 1) {
$name = mysql_result($result, 0, ’em_name’);
setcookie(“auth”, “1”, 0, “/”, “localhost”, 0);
$display_block = “<p>hello $em_name!</p>”;
}
else {
//redirect back to home page if login not found
header(“location: homepage.php”);
exit;
}
?>
<HTML>
<Title>User login</title>
</head>
<body>
<? echo “$msg”; ?>
</BODY>
</HTML>