function validateRegistration($conn, $registration_form) { if (isNullOrEmpty($registration_form['gamertag']) || !checkGamertagAvailability($conn, $registration_form['gamertag']) || isNullOrEmpty($registration_form['first_name']) || isNullOrEmpty($registration_form['last_name']) || isNullOrEmpty($registration_form['last_name']) || isNullOrEmpty($registration_form['email']) || !filter_var($registration_form['email'], FILTER_VALIDATE_EMAIL) || !checkEmailAvailability($conn, $registration_form['email']) || isNullOrEmpty($registration_form['city']) || isNullOrEmpty($registration_form['state']) || isNullOrEmpty($registration_form['skill']) || !is_numeric($registration_form['skill']) || !is_numeric($registration_form['melee_setups']) || !is_numeric($registration_form['projectm_setups']) || !is_numeric($registration_form['tvs'])) { return false; } return true; }
function validatePortalUpdate($conn, $portal_form) { if (isNullOrEmpty($portal_form['gamertag']) || strlen($portal_form['gamertag']) > 25 || !checkGamertagAvailability($conn, $portal_form['gamertag'])) { return false; } if (!is_null($portal_form['pm_doubles'])) { if (!filter_var($portal_form['pm_teammate'], FILTER_VALIDATE_EMAIL)) { return false; } } if (!is_null($portal_form['melee_doubles'])) { if (!filter_var($portal_form['melee_teammate'], FILTER_VALIDATE_EMAIL)) { return false; } } return true; }
// creates mysqli in $conn function checkGamertagAvailability($conn, $gamertag) { if (is_null($gamertag)) { return false; } if (isset($_SESSION['auth'])) { if ($gamertag == $_SESSION['auth']['tag']) { return true; } } $query = "SELECT id FROM registration WHERE tag=?"; $stmt = $conn->prepare($query); $stmt->bind_param("s", $gamertag); if ($stmt->execute()) { if ($stmt->store_result()) { if ($stmt->num_rows == 0) { return true; } } } return false; } if (isset($_GET['jscheck'])) { $gamertag = $_POST['gamertag']; if (checkGamertagAvailability($conn, $gamertag)) { echo "1"; } else { echo "0"; } }