function clear_input($input_data) { if (is_array($input_data)) { foreach ($input_data as $key => $value) { $output_data[$key] = clear_input($input_data[$key]); } } else { if (get_magic_quotes_gpc() == 1) { stripslashes($input_data); } $output_data = mysql_real_escape_string(trim($input_data)); } return $output_data; }
$firstname = $lastname = $email = $grade = $class = ""; $data_ok = true; //removes space, tab and newline and avoids cross-site scripting, sql-injections etc. function clear_input($data, $conn) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); $data = mysqli_real_escape_string($conn, $data); return $data; } $firstname = clear_input($_POST["firstname"], $conn); $lastname = clear_input($_POST["lastname"], $conn); $email = clear_input($_POST["email"], $conn); $grade = clear_input($_POST["grade"], $conn); $class = clear_input($_POST["class"], $conn); //Check if a field was left empty if (empty($firstname)) { $data_ok = false; echo "<div class='alert alert-warning'>Bitte gib deinen Vornamen an!</div>"; } if (empty($lastname)) { $data_ok = false; echo "<div class='alert alert-warning'>Bitte gib deinen Nachnamen an!</div>"; } if (empty($email)) { $data_ok = false; echo "<div class='alert alert-warning'>Bitte gib deine Mailadresse an!</div>"; } else { if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $data_ok = false;