How do I add a PHP code that will always open/create a new text file and write user input once user clicks 'Submit' button.
This is the html code
<form action="save_redirect.php" id="#form" method="post" name="#form">
<label>Email:</label><br>
<input id="email" name="email" placeholder='Enter A Valid Email Address' type='text'>
<br>
<input id='btn' name="submit" type='submit' value='Submit'>
<?php
include "include/redirect.php";
?>
</form>
This is the php code I already wrote for redirecting.
<?php
if(isset($_POST['submit'])) {
// Fetching variable of the form which travels in URL
$email = $_POST['email'];
$myfile = fopen("text.txt", "w");
fwrite($myfile, $email);
fclose($myfile);
if($email !='') {
header("Location:https://www.formget.com/app/");
}
else {
?><span><?php echo "Please fill the email field! This is where you'll receive script files on.";?></span> <?php
}
}
?>
Use uniqid()
to generate a unique filename. And you can use file_put_contents()
to combine fopen()/fwrite()/fclose()
.
$filename = uniqid() . ".txt";
file_put_contents($filename, $email);
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments