Currently creating a login form with php, I am currently trying to get it so once correct details are in it redirects them to home. I can’t seem to find why it’s not working though, perhaps I am missing something?
<?php
$con = mysqli_connect('localhost', 'host', 'pass', 'host')
or die("can't connect");
session_start();
if(isset($_POST['login'])) {
// username and password sent from form
$email = $_POST['email'];
$password = $_POST['password'];
$email = mysqli_real_escape_string($con, $email);
$password = mysqli_real_escape_string($con, $password);
$query = "SELECT * FROM accounts WHERE email = '$email' and password = '$password'";
$select_user_query = mysqli_query($con, $query);
if(!$select_user_query) {
die("QUERY FAILED". mysqli_error($con));
}
while($row = mysqli_fetch_array($select_user_query)) {
$user_email = $row['email'];
$user_password = $row['password'];
$user_fname = $row['fname'];
$user_lname = $row['lname'];
$user_dob = $row['dob'];
}
if($email == $user_email && $password == $user_password) {
header("Location: ../index.php");
}
else if ($email !== $user_email && $password !== $user_password) {
header("Location: ../login.php");
}
}
?>