I'm trying to do an email validation.
I've got an input text field which I write to a file when the user enters data into the input field.
I would like to have a simple code which would check if the email is valid, and if the email isn't valid go back to the original page and don't add it to the .txt file
Currently I have:
// only do file operations when appropriate
if(isset($_POST['email']) && (filter_var($a, FILTER_VALIDATE_EMAIL)) {
$a = $_POST['email'];
$myFile = "email.txt";
$fh = fopen($myFile, 'a') or die("can't open file");
fwrite($fh, $a);
fclose($fh);
}
else
{
echo "Email is not Valid" . "<script>history.back()</script>";
}
As you can see I haven't figured out how to not add it to the text file yet, however I would like to just get the email filter working first. Could anyone help me with this problem?
Edit: I also keep getting the error:
Parse Error: syntax error, unexpected '{' in "C:.......\authorized.php on line 59
Which is the opening bracket to the if statement?