I am using fwrite() to write to a .txt file.
I have a home page which displays the text from the .txt file. seems to be working ok.
I then have an 'admin' page which on submit, will fwrite() the contents of my textarea to the file... by default on page load, the textarea will display the current contents of the .txt file but every time i click submit the text is added ok, but with a number value after it, it seems to be counting the characters as if starting from 0.
For example:
I type 'Hello' and submit/ homepage displays 'Hello' / Textarea displays 'Hello5'
...If i then click the submit button again
homepage displays 'Hello5' / Textarea displays 'Hello56'
and so on....
i cant seem to work out why.
This is what i have so far....
<?php
if(isset($_POST['submit1'])) {
$welcomeText=fopen("writetofile.txt", "w+");
$file_contents=$_POST['welcomeText'];
fwrite($welcomeText, $file_contents);
fclose($welcomeText);
}
?>
<form name="welcomeTextEditor" method="post" action="_admin.php">
<textarea name="welcomeText" rows="4" cols="40"><?php echo(readfile("writetofile.txt")); ?></textarea>
<br />
<input type="submit" name="submit1" value="Save Changes" />
</form>