When a user enters the page in question, a textarea is populated from data from a text file stored on the server. The user can then edit that text (add, erase all or part, and modifiy). When the submit button is clicked, the edited text is written back into the same file from which it came. The code below works. The only problem is that on clicking the submit button, not only is the text saved, but the modifications made by the user disappear from the text box. This givess the user the impression that his/her work in editing the text is gone. Is there any way that the modifications made to the data in the text box can remain after the submit button is clicked?
<body>
<?php $oldtext = file_get_contents('filltext.txt');
?>
<form name="for PHP" method="POST">
<textarea name="PHP_testing" cols="60" rows="10" id="testing">
<?php echo $oldtext;
?>
</textarea>
<input type="submit" name="submit" value="Save Text"/></input>
</form>
<?php
if(isset($_POST['submit'])){
$newtext=$_POST['PHP_testing'];
file_put_contents('filltext.txt',$newtext);
echo "The modified text has been saved.";
}
?>
</body>