Login System Error - PDO
I'm having an issue with my login system using PDO. When you login with
the correct password, it will just refresh the page even though the form
is linked to another page & when you login you'll be redirected to
"home.php" not "index.php"
include('./includes/connect.php');
$submit = $_POST['submit'];
$email = sanitize($_POST['email']);
$password = nCrypt(sanitize($_POST['password']));
if(isset($submit)) {
if(isset($email) && isset($password)) {
$query = $pdo->prepare("SELECT password FROM users WHERE email = ?");
$query->bindValue(1, $email);
$query->execute();
$r = $query->fetch();
$pass2 = $r['password'];
$first = $r['first'];
$last = $r['lastname'];
$username = $r['username'];
if(strcasecmp($password, $pass2) == 0) {
$_SESSION['user'] = $r['user'];
$_SESSION['first'] = $r['first'];
$_SESSION['last'] = $r['last'];
$_SESSION['id'] = $r['id'];
header('Location: home.php');
} else {
header('Location: index.php?e=incorrect');
}
} else {
header('Location: index.php?e=empty');
}
}
?>
Basically, when you enter the correct password nothing happens. My form is:
<!-- index.php -->
<form action="login.php" method="POST">
<legend>Email Address</legend>
<input type="email" name="email" placeholder="Email Address"
required><br>
<legend>Password</legend>
<input type="password" name="password" placeholder="Password"
required><br>
<input class="btn btn-info" type="submit" name="submit" value="Login">
</form>
As you can see it links to another page, yet when when you enter in the
correct password, it'll just refresh the page the form is on, when it
suppose to redirect you to "home.php".
No comments:
Post a Comment