My else statement where I have the header going back to test.php page isn't working and I don't have any idea why but the if/true statement is working fine and sending the person to the passengerHome.php page when they entered the correct credentials
<?php
//Feedback variable to update user of system status
$feedback= "";
//retrieve the details from the POST Global Variable
$user = $_POST['username'];
$pass = $_POST['password'];
validate($user, $pass);
if($feedback != ""){
Header("Location:../presentation/passengerLogin.php?feedbackMsg=$feedback");
}else {//check the database to see if the username and password combination matches
//clean and format the data
sanitize($user);
sanitize($pass);
//include connection string
include("../data/dbConnection.php");
if ($stmt = mysqli_prepare($mysqli, "SELECT commuteType, status, passengerID FROM tblPassenger WHERE username = ? AND password = ?"))
//bind parameters for markers
mysqli_stmt_bind_param($stmt, "ss", $user, $pass);
//execute query
mysqli_stmt_execute($stmt);
//bind value holders to result set
mysqli_stmt_bind_result($stmt, $ct, $status, $passenger);
if (mysqli_stmt_fetch($stmt))
{
session_start();
$_SESSION['commuteType'] = $ct;
$_SESSION['status'] = $status;
$_SESSION['passengerID'] = $passenger;
if ($ct == "passenger" && $status == 1 && $passenger != "") {
Header("Location: ../presentation/passengerHome.php");
}else{
Header("Location: ../presentation/test.php");
}
}
}
//Function to SANITIZE (Clean) datax`
function sanitize($data){
$data = trim($data);
$data = stripslashes($data);
$data = filter_var($data, FILTER_SANITIZE_SPECIAL_CHARS);
$data = filter_var($data, FILTER_SANITIZE_STRING);
$data = filter_var($data, FILTER_SANITIZE_STRING);
$data = filter_var($data, FILTER_SANITIZE_STRING);
//for,at data for storage (maintain uniformity)
$data = strtolower($data);
$data = ucfirst($data);
//validate($first, $last, $gen, $a, $user, $pass, $em, $add);
//finally... return the cleaned and formatted data
return $data;
}//end sanitize function
function validate($userVal, $passVal){
global $feedback;
if($userVal == null || $userVal == ""){
$feedback .= "Username required<br/>";
}else {
$feedback .= "";
}
if($passVal == null || $passVal == ""){
$feedback .= "Password required<br/>";
}else {
$feedback .= "";
}
}
?>