Hello I have been encountering this bug for a long time. So basically here is by code:
function loginUser($conn, $username, $password) {
$checkExists = checkExists($conn, $username, $username);
if ($checkExists === false) {
header("Location: ../login.php?error=wronglogininfo");
exit();
}
$passwordHashed = $checkExists['password'];
$checkPassword = password_verify($password, $passwordHashed);
if ($checkPassword === false) {
header("Location: ../login.php?error=wronglogin");
exit();
} elseif ($checkPassword === true) {
$query = "SELECT * FROM users WHERE username='$username' AND password='$checkPassword'";
$query_run = mysqli_query($conn, $query);
$usertypes = mysqli_fetch_array($query_run);
if ($usertypes['usertype'] == "admin") {
header('Location: ../login.php?admin');
} elseif ($usertypes['usertype'] == "user") {
header('Location: ../login.php?user');
}
}
}
function checkExists($conn, $username, $email) {
$sql = "SELECT * FROM users WHERE username = ? OR email = ?;";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql)) {
header("Location: ../register.php?error=stmtfailed");
exit();
}
mysqli_stmt_bind_param($stmt, "ss", $username, $email);
mysqli_stmt_execute($stmt);
$resultData = mysqli_stmt_get_result($stmt);
if ($row = mysqli_fetch_assoc($resultData)) {
return $row;
} else {
$result = false;
return $result;
}
mysqli_stmt_close($stmt);
}
And so the errors work fine. The real problem is that whenever I login with correct credentials it sends me to a 404 page with a directory I never put. I want it to send be to the admin panel or user page. Can anyone help?