connect_error) { exit("Connection failed: " . $conn->connect_error); } if(isset($_POST['ID']) && isset($_POST['password'])) { $id = trim($_POST['ID']); //trim spaces $pass = trim($_POST['password']); //trim spaces if(empty($id)) { //if the id is empty send the user back to the login page with an error message header("Location: coach_index.php?error=6-Letter ID is Required"); exit(); } else if (empty($pass)) { //if the password is empty send the user back to the login page with an error message header("Location: coach_index.php?error=Password is Required"); exit(); } else { //SQL Query to find if the ID and password entered is in the database. $sql = "SELECT C_ID, C_L_Name, password FROM Coaches WHERE C_ID = '$id' AND password = '$pass'"; //Sending the query $results = $conn->query($sql); if(mysqli_num_rows($results) == 1)//only one row should be returned { $row = $results->fetch_assoc(); if($row['C_ID'] == $id && $row['password'] == $pass) { echo 'Logged In!!'; $_SESSION['id'] = $row['C_ID']; $_SESSION['coach'] = $row['C_L_Name']; header("Location: info_page.php?welcome=1"); exit(); } else { header("Location: coach_index.php?error=Incorrect Username or Password"); exit(); } } else { header("Location: coach_index.php?error=Incorrect Username or Password"); exit(); } } } ?>