This question already has an answer here:
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, "
");
}
fwrite($handle, "
");
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?
</div>
Here, $email is not defined, so you should add this before the if statement:
$email = $_POST['email']; // here 'email' is the field name in your HTML page