I'm sorry, I know this has been asked over and over, but I can't find a thread where people aren't arguing about the possibility of writing files with PHP or javascript. You get people saying "IMPOSSIBLE!" and others saying "POSSIBLE under these conditions". The answers on these threads that contain code don't work when I try to include them in my simple webpage, so I just want to post my snippet of code, my attempt at writing a text file, and see if anyone can tell me why it doesn't work and whether it is even possible.
My goal is to get the page to take each submission, and write all the text fields on one line in a text document, put in a line-return, and save/close the file. So each time something is submitted, a new single line is added for each submission.
<script>
<?php
if(isset($_POST['write'])) {
$f = fopen("log.txt", "a");
fwrite($f, $_POST["fName"]);
fwrite($f, $_POST["lName"]);
fwrite($f, $_POST["sessionDate"]);
fwrite($f, $_POST["fName"]);
fwrite($f, "\n");
fclose($f);
die():
}
?>
</script>
<form method="post" action="?write">
<input name="fName" type="text" placeholder="FIRST NAME"/>
<input name="lName" type="text" placeholder="LAST NAME"/>
<input name="sessionDate" type="date"/>
<input name="workoutPerformed" type="text" placeholder="WORKOUT PERFORMED"/>
<button name="submitButton" class="checkinButton" type="submit">SUBMIT</button>
</form>
I'm running these files in a local directory on my computer, and when I can determine that everyone works as intended to put them on a webpage to keep track of my business' member check