title: I cannot able to validate the form using the above code in PHP (PHP FORM VALIDATION)
body: <p>I wanted to validate the form in PHP but it doesn't give any output from validate.php</p>
  
  <p>this PHP code didn't give any output after submitting the Form 
  help me with this form validation</p>
  
  <blockquote>
    <p>validate.php</p>
  </blockquote>
  
  <pre><code>    function validate($data, $reg_exp = "") {
        $data = trim($data);
        $data = stripslashes($data);
        $data = htmlspecialchars($data);
        if (empty($data) == true) {
          $Err = "EMT_FLD";
          return false;
        } else{
          if ($reg_exp != "") {
            if (preg_match($reg_exp, $data) !== true) {
              $Err = "PRG_MTH_ERR";
              return false;
            } else {
               return true ;
              return $data;
            }
          }else {
            return true ;
            return $data;
          }
        }
      }
  </code></pre>
  
  <blockquote>
    <p>register.php</p>
  </blockquote>
  
  <pre><code>      include 'validate.php';
  
            if ($_SERVER['REQUEST_METHOD'] == 'POST') {
                $fnErr = $lnErr = $unErr = $emErr = $psErr = $cpErr = "";
                $submit = false;
  
                if ($val = validate($_POST['firstname'],"/^['a-zA-Z']+$/")) {
                    if ($val == false) {
                      if($Err == "EMT_FLD"){
                        $fnErr = "&lt;span class = 'error'&gt;First Name Required&lt;/span&gt;";
                      }
                      if($Err == "PRG_MTH_ERR") {
                        $fnErr = "&lt;span class = 'error'&gt;Invalid First Name, Only Letters Are Allowed (A-Z and a-z)&lt;/span&gt;";
                      }
                    }elseif($val == true){
                      $firstname = $_POST['firstname'];
                    }
                }
            }
  
       echo $fnErr."&lt;br&gt;"; 
  </code></pre>
  
  <p>Expected: It Should Return the <code>$fnErr</code>, But It Returns Nothing</p>