Im making a login system for my website, in newer to php coding and when i press my login button it sends me with the "login.php?error=nouser" in the url when my email is in my database, im not sure if i messed up with some code or something needs to be moved around or not. I am new to php and dont have a eye good enough to spot some of these problems.
<?php
if (isset($_POST['login-submit'])) {
require 'dbh.inc.php';
$emailuid = $_POST['emailuid'];
$password = $_POST['pwduid'];
if (empty($emailuid) || empty($password)) {
header("Location: ../login.php?error=emptyfields&emailuid=".$emailuid);
exit();
} else {
$sql = "SELECT * FROM users WHERE emailUsers=?";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql)) {
header("Location: ../login.php?error=sqlerror");
exit();
} else {
mysqli_stmt_bind_param($stmt, "ss", $emailuid, $emailuid);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
if ($row = mysqli_fetch_assoc($result)) {
$pwdCheck = password_verify($password, $row['pwdUsers']);
if ($pwdCheck == flase) {
header("Location: ../login.php?error=wrongpassword");
exit();
} elseif ($pwdCheck == true) {
session_start();
$_SESSION['userId'] = $row['idUsers'];
$_SESSION['userfnId'] = $row['fnidUsers'];
$_SESSION['userlnId'] = $row['lnidUsers'];
header("Location: ../login.php?login=success");
exit();
} else {
header("Location: ../login.php?error=wrongpassword");
exit();
}
} else {
header("Location: ../login.php?error=nouser");
exit();
}
}
}
} else {
header("Location: ../login.php");
exit();
}
Any type of help is appreciated, im learning how this all works. thanks for the understanding.