So I cant work out whats wrong with my PHP which is causing this problem. As you'll see from the code, I had it echo based on the if statements. If the details are equal to the query then it will echo Test2 which it does. But why doesnt it redirect? I cant figure out what's wrong.
<?php
include "../inc/db.php";
include "../inc/functions.php";
$tip = "";
if(isset($_POST["submit"])) {
$username = $_POST["username"];
$password = $_POST["password"];
$username = mysqli_real_escape_string($connection, $username);
$password = mysqli_real_escape_string($connection, $password);
$query = "SELECT * FROM users WHERE username = '{$username}' ";
$select_user_query = mysqli_query($connection, $query);
if(!$select_user_query) {
die("Query failed. Reason: " . mysqli_error($connection));
}
while($row = mysqli_fetch_array($select_user_query)) {
$db_user_id = $row['id'];
$db_username = $row['username'];
$db_password = $row['password'];
}
if($username !== $db_username && $password !== $db_password ) {
header("Location index.php");
$tip = "Incorrect details!";
echo "Test1";
} elseif ($username == $db_username && $password == $db_password) {
header("Location ");
echo "Test2";
} else {
header("Location index.php");
echo "Test3";
}
}
?>
Result of submitting the correct details:
and proof that dashboard.php does exist
if I enter something that doesnt exist in the mysql database then I get this:
but I defined the variable in the while loop