I wrote a html form just with an email field. I want to transfer that email that the user inputs into a text file on my web server.
When I click on the submit button I get a white screen. Nothing is written to my text file. I also want to redirect the user to another page when they click the submit button. Is this possible? I am a newbie.
<?php
$file = fopen("emaillist.txt","a+");
fwrite($file,$email);
fclose($file);
print_r(error_get_last());
?>
<form action= "emaillist.php" method="post" name="email ">
<input type="text" name="email">
<br>
<br>
<input type="submit" name="email" value="submit"><br>
In addition to what Andy G said about changing the name of submit button:
<?php
//Get the email from POST
$email = $_REQUEST['email'];
$file = fopen("emaillist.txt","a+");
fwrite($file,$email);
print_r(error_get_last());
//redirect
header("Location: http://www.example.com/");
Don't leave any blank lines between <?php and the beginning of the file, otherwise redirect won't work.
In php theres an array called $_POST that stores all of the variables from a form when you post it. So $email would be found in $_POST['email']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With