title: Getting error message before entering text in textbox
body: <p>In below code I am getting error message <code>Sorry your name is not in correct format</code> even before I enter any text. Can anyone tell me what mistake am I making ?</p>
  
  <pre><code>if ((isset($_POST['name'])) and(isset($_POST['email'])) and (filter_var($email, FILTER_VALIDATE_EMAIL)) and (preg_match('/^[A-Za-z0-9\s]+$/', $name))) {
  
      //if yes, it is writing it into file
      $myfile = fopen("names.txt", "w") or die("Unable to open file!");
      $txt = $name . "\r\n" . $email;
      fwrite($myfile, $txt);
  
      fclose($myfile);
  }
  else {
      echo "Sorry, your name is not in correct format.";
  }
  </code></pre>