I have the following code:
<?php
$email = $_POST['email'];
if ($email!=='ThisMail'){
header ('Location:http://www.mywebsite.com/');
$handle = fopen("data.txt", "a");
foreach($_POST as $variable => $value) {
fwrite($handle, $variable);
fwrite($handle, "=");
fwrite($handle, $value);
fwrite($handle, "\r\n");
}
fwrite($handle, "\r\n");
fclose($handle);
exit;
}
else{
header ('Location:http://www.google.com/');
exit;
}
?>
I am basically collecting information from a form on my website, with action=form.php
(where this code is saved). I want it so that if the email field on my HTML document where the form is is filled out with a particular email address, ThisMail
, it will write all the stored data from the form in the file data.txt
and redirect to the webpage I want.
The other side of the if statement simply redirects the user to another page.
This does not seem to be working for me. How can I fix this?