Hi All,
I have created a user_login.php file to act as a login page for users accessing the application. However if I type a username and password into the login form, the script displays incorrect username/password. I have checked the database and when I register a user and then try and login with that user, the script doesn't recognise the user. I don't know whether it is down to the session expiring or the database isn't being accessed. Any help appreciated.
<?php
session_start();
include "conn.inc.php";
if (isset($_POST['submit']) && $_POST['submit'] == "Login") {
$query = "SELECT * FROM lecturer " .
"WHERE username = ' " . $_POST['username'] . " ' " .
"AND password = (PASSWORD(' " . $_POST['password'] . " '))";
$result = mysql_query($query)
or die(mysql_error());
if (mysql_num_rows($result) == 1) {
$_SESSION['user_logged'] = $_POST['username'];
$_SESSION['user_password'] = $_POST['password'];
header ("Refresh: 5; URL=" . $_POST['redirect'] . " ");
echo "You are being redirected to your original page request!<br>";
echo "(If your browser doesn't support this, " .
"<a href=\" " . $_POST['redirect'] . "\">Click here</a>)";
} else {
?>
<html>
<head>
<title>Final Year Project Application - Login</title>
</head>
<body>
<p>
<font color="#FF0000"><b> You have entered an incorrect username and/or password</b></font>
<form action="user_login.php" method="post">
<input type="hidden" name="redirect"
value="<?php echo $_POST['redirect']; ?>">
Username: <input type="text" name="username"><br>
Password: <input type="password" name="password"><br><br>
<input type="submit" name="submit" value="Login">
</form>
</p>
</body>
</html>
<?php
}
} else {
if(isset($_GET['redirect'])) {
$redirect = $_GET['redirect'];
} else {
$redirect = "index.php";
}
?>
<html>
<head>
<title>Final Year Project Application - Login</title>
</head>
<body>
<p>
Please enter your username and password below:<br><br><br>
<form action="user_login.php" method="post">
<input type="hidden" name="redirect"
value="<?php echo $redirect; ?>">
Username: <input type="text" name="username"><br>
Password: <input type="password" name="password"><br><br>
<input type="submit" name="submit" value="Login">
</form>
</p>
</body>
</html>
<?php
}
?>
Here is the lecturer table layout:
id int(5) auto_increment
username varchar(9)
first_name varchar(30)
last_name varchar(50)
password varchar(8)
email varchar(50)