validation not working in php on submission the form data by click the submit button plz help me by explaination :         validation not working in php  on submission the form data by click the submit button plz help me by explaination
    <?php    
        if (isset($_POST['validate'])) {
            	if (empty($_POST['ename'])){
            		$nameErr = "name is required";
            	}
            	else{
            		$name = test_input($_POST['ename']);
            		 if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
                  $nameErr = "Only letters and white space allowed"; 
                }
            		}
            	if (empty($_POST['mail'])){
            		$emailErr = "email is required";
            		}
            	else{
            		$email = test_input($_POST['mail']);
            	}
            	if (empty($_POST['gender'])){
            		$genderErr = "gender is required";
            	}
            	else{
            		$gender = test_input($_POST['gender']);
            	}
i want stop empty insertion
            	$query = "insert into inserttb (name,email,gender) values ('$name','$email','$gender')";
            	$result = mysqli_query($conn,$query);
            	if(!$result){
            	echo "data insertion failed";
            	}
            	}
            	//function to validate the input data
            	function test_input($data) {
            	  $data = trim($data);
            	  $data = stripslashes($data);
            	  $data = htmlspecialchars($data);
            	  return $data;
            	}
            ?>