form validation in php

Solutions on MaxInterview for form validation in php by the best coders in the world

showing results for - "form validation in php"
Valeria
17 Sep 2017
1 <?php
2// define variables and set to empty values
3$name = $email = $gender = $comment = $website = "";
4
5if ($_SERVER["REQUEST_METHOD"] == "POST") {
6  $name = test_input($_POST["name"]);
7  $email = test_input($_POST["email"]);
8
9  
10 $website = test_input($_POST["website"]);
11  $comment = test_input($_POST["comment"]);
12  $gender = test_input($_POST["gender"]);
13}
14
15 //php form data validation function 
16function test_input($data) {
17  $data = trim($data);
18  $data = stripslashes($data);
19  $data = htmlspecialchars($data);
20  return $data;
21
22 }
23?>