I want to check if record exists and if it does then go to page A, otherwise go to page B. But it just always goes to page A whether there is a record or not.
<?php
$ini = parse_ini_file("../phpconfig.ini");
$conn = mysqli_connect($ini['hostaddress'], $ini['username'], $ini['password'], $ini['databasename']);
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$options = ['cost' => 10,];
$number = mysqli_real_escape_string($conn, $_POST['number']);
$password = password_hash((mysqli_real_escape_string($conn, $_POST['password'])), PASSWORD_BCRYPT, $options);
$sql = "INSERT INTO usertemp (Employee_Number, Password)
VALUES ('$number', '$password')";
if (mysqli_query($conn, $sql)) {
$sql2 = "SELECT EXISTS(SELECT 1 FROM employee WHERE Number = '$number')";
$row2 = mysqli_query($conn, $sql2);
if (mysqli_num_rows($row2) > 0) {
//Has record in Employee table
header("location: display_createaccount_a.php");
} else {
//No record in Employee table
header("location: display_createaccount_b.php");
}
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
mysqli_close($conn);
?>