$_SESSION["username"],"message_content"=>$_POST["message_content"]]; if (isEmpty($inputs)) { $errors = ["null_field" => "Form contains blank characters."]; } if (!user_exists($pdo, $inputs["username"])) { $errors = ["inexistent_user" => "User does not exist on db."]; } } else { $errors = ["not_logged_in" => "You haven't logged in."]; } if ($errors) { $_SESSION["errors"] = $errors; // Send back form $entered_data = [ "message_content" => $inputs["message_content"] ]; $_SESSION["entered_chat_data"] = $entered_data; header("Location: ../chat.php"); $inputs = null; die(); } send_message($pdo, $inputs["username"], $inputs["message_content"]); header("Location: ../chat.php"); $inputs = null; die(); } catch (PDOException $e) { echo "An error has ocurred: " . $e->getMessage(); exit(); } } else { echo "Wrong request type, please check your request."; exit(); }