In below code I am getting error message Sorry your name is not in correct format
even before I enter any text. Can anyone tell me what mistake am I making ?
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.";
}