Hey guys!
I have a page that has multiple forms. I am trying to make a button that will save all the information from each textarea to a different .txt file.
IE: textarea1 will save to textarea1.txt
textarea2 will save to textarea2.txt
textarea3 will save to textarea3.txt
etc.
I am able to save each individual form via individual submit buttons within each form, but I'd like to make a submit button outside of the other forms that saves all forms to their specific files.
The code for one of the individual forms looks like this:
<form method="post" action="?">
<h1>Physical Stats</h1>
<textarea name="stats"><?php include ('resources/stats.txt'); ?></textarea>
<br><input type="submit" name="update_stats" value="Update"/>
</form>
<?php
if (isset($_POST['update_stats'])) {
file_put_contents("resources/stats.txt", $_POST['stats']); } ?>
Everything above works.
And the code for the save all form looks like this:
<form method="post" action="?">
<input type="submit" name="update_all" value="Update All"/>
<br><br>
</form>
<?php
if (isset($_POST['update_all'])) {
file_put_contents("resources/stats.txt", $_POST['stats']);
file_put_contents("resources/pro_exp.txt", $_POST['pro_exp']);
file_put_contents("resources/pro_awards.txt", $_POST['pro_awards']);
file_put_contents("resources/ama_exp.txt", $_POST['ama_exp']);
file_put_contents("resources/ama_awards.txt", $_POST['ama_awards']);
file_put_contents("resources/references.txt", $_POST['references']); }
?>
This is the code I currently have and it's just not working. Right now the above code is actually clearing all of the text files. I'm afraid I'm a complete newb to writing scripts and I'm sure there is some rule about file_get_contents that I'm not aware of.
Please help! Thanks!