This is my code:
<?php
//check if the form allows user input to be extracted
if(isset($_POST['email']))
//if so loop begins
{
//creates a variable called $data that contains the user input for a particular input name from the form
//writes to txt file
$myfile = fopen("form.txt", "w") or die("Unable to open file!");
$email = "Email: ";
fwrite($myfile, $email);
fclose($myfile);
//appends to txt file
$data=$_POST['email'];
//creates a variable called $fp that contains the function fopen which opens a file called form.txt
$fp = fopen('form.txt', 'a');
//initiates the function fwrite which displays the user input in the txt file
fwrite($fp, $data); //when echo in html use div center tag
//closes txt file with the function fclose
fclose($fp);
}
if(isset($_POST['title']))
{
$data=$_POST['title'];
$fp = fopen('form.txt', 'a');
fwrite($fp, $data);
fclose($fp);
}
if(isset($_POST['date']))
{
$data=$_POST['date'];
$fp = fopen('form.txt', 'a');
fwrite($fp, $data);
fclose($fp);
}
if(isset($_POST['link']))
{
$data=$_POST['link'];
$fp = fopen('form.txt', 'a');
fwrite($fp, $data);
fclose($fp);
}
?>
I want to know how to write the user input to the txt file in php with a space between the header and the input and a linebreak after every one. Whenever I try to use the 'w' more than once the text from the first time it was used is not displayed.