I've created a simple form and some PHP to handle it and write to the server:
<div class="main">
<div class= "formholder">
<form action="phone.php" method="get">
<input type="text" placeholder= "First Name:" name="forename" required><br>
<input type="text" placeholder= "Last Name:" name="surname" required><br>
<input type="text" maxlength="12" placeholder="Phone Number: +44" name="phone" required><br>
<input type="submit">
</form>
</div>
</div>
The PHP I'm using is as follows:
<?php
$forename = $_POST["forename"];
$surname = $_POST["surname"];
$phone = $_POST["phone"];
$text = "NAME: $forename $surname <br>
PHONE: $phone<br>";
$file = fopen("./data/responses.html","a+");
fwrite($file, $text);
fclose($file);
?>
Whenever a response is submitted the server adds the field names to the responses.html
document, but not the data that the user submitted.
The result in the file is;
NAME: <br>
PHONE: <br>
It adds the fields each time, just not the user inputs. Any ideas why? Thanks in advance.
EDIT 1, NEWLINES
I'm trying to make it so that after each response the code starts a new line. I've tried this;
<?php
$file = fopen("./data/responses.html","a+ /n");
fwrite($file, $text);
fclose($file);
?>
Currently the response doc looks like this:
<!--Phone Number Responses-->NAME: Name1 Name1 <br>PHONE: Phone1 <!--Next Person:--><br>NAME: Name2 Name2 <br>PHONE: Name2 <!--Next Person:--><br>
But I'd prefer a new line started for each response;
<!--Phone Number Responses-->
NAME: Name1 Name1 <br>PHONE: Phone1 <!--Next Person:--><br>
NAME: Name2 Name2 <br>PHONE: Name2 <!--Next Person:--><br>
And so on. I added the <!--Next Person:-->
comment to differentiate because they all save to the same line.