moe Posted March 27, 2008 Share Posted March 27, 2008 Hi Guys; I am trying to read a text file into a text area allow changes to the text then save the text back to the file on submit. (hope that makes sense ) Here is the code: <?php if($_POST['addition']){ $file_name = "something.txt"; $file_open = fopen("something.txt","a+"); fwrite($file_open, $_POST['addition']); fclose($file_open); } ?> <form action="<?=$PHP_SELF?>" method="POST"> <textarea name="addition" COLS=40 ROWS=6> <?php $datalines = file ("something.txt"); foreach ($datalines as $zz) { echo $zz; } ?> </textarea> <input type="submit" name="addition"> It does not seem to be saving the text back. Any help would be great. Oh yeah this is a multi-line (list) text file - as in: 1 2 3 4 etc etc Cheers; Moe Quote Link to comment Share on other sites More sharing options...
ansarka Posted March 27, 2008 Share Posted March 27, 2008 you have given same name for submit button and text area also make sure that you hv write permission to file below code is working try it <?php if($_POST['addition']){ $file_open = fopen("something.txt","w+"); //fopen("something.txt","a+"); to add the contents to file fwrite($file_open, $_POST['addition']); fclose($file_open); } ?> <form action="<?=$PHP_SELF?>" method="POST"> <textarea name="addition" COLS=40 ROWS=6> <?php $datalines = file ("something.txt"); foreach ($datalines as $zz) { echo $zz; } ?> </textarea> <input type="submit" name="button"> </form> ;) ;) Quote Link to comment Share on other sites More sharing options...
moe Posted March 31, 2008 Author Share Posted March 31, 2008 Thanks a lot for the help this now works a treat..now to keep adding and modifying as a create my pages...I am sure I will be back if if have any more problems. Thanks again. Moe Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.