Hello everyone I been searching for this for a while now but I cant find anything. Please if its out there somewhere , guide me! I want to a php page, lets says "form.php" when I open that page it only has a text box and a SAVE button. When I type in that box and press "Save" it will save the text in a file called "data.txt". So next time I login to form.php the data I saved previously is in that box, so then I could just finish my typing or edit. Please help, Thanks
Here is code for what you are talking about. <?php $saving = $_REQUEST['saving']; if ($saving == 1) { $data = $_POST['data']; $file = "data.txt"; $fp = fopen($file, "w") or die("Couldn't open $file for writing!"); fwrite($fp, $data) or die("Couldn't write values to file!"); fclose($fp); echo "Saved to $file successfully!"; } ?> <form name="form1" method="post" action="form.php?saving=1"> <textarea name="data" cols="100" rows="10"> <?php $file = "data.txt"; if (!empty($file)) { $file = file_get_contents("$file"); echo $file; } ?> </textarea> <br> <input type="submit" value="Save"> </form> Code (markup):
Thanks RIZZY!!! Your awesome. One problem though, for example, if I add this to the form <br><font color="#808080"> PHP: and then Press Save, it comes out like this <br><font color=\\\"#808080\\\"> PHP: Each time I press SAVE these the blackslashes double, triple, and so on. How can I fix this problem? Thanks again
You don't need the urldecode, just the strip slashes <?php $saving = $_REQUEST['saving']; if ($saving == 1) { $data = $_POST['data']; $file = "data.txt"; $fp = fopen($file, "w") or die("Couldn't open $file for writing!"); fwrite($fp, $data) or die("Couldn't write values to file!"); fclose($fp); echo "Saved to $file successfully!"; } ?> <form name="form1" method="post" action="form.php?saving=1"> <textarea name="data" cols="100" rows="10"> <?php $file = "data.txt"; if (!empty($file)) { $file = file_get_contents("$file"); echo stripslashes($file); } ?> </textarea> <br> <input type="submit" value="Save"> </form> Code (markup):
dunno if it's of any use to you but another thing you could implement is replacing <br>s with new lines using nl2br()