I'm rather new to PHP and i've created a guestbook style script for users to give feedback on an article im doing.
Everything is fine so far, and it works.. but i'm having a slight problem storing all the data from the forms.
Im using a .txt file and fopen, fputs etc to store the form data inside the .txt file. I can get it working fine using:
$data = fopen ($datafile, "a+");
fputs ($data, $storedata);
But i want new comments up the top, so i want it to store new entries at the top of the file and not at the bottom... so i use:
$data = fopen ($datafile, "w+");
fputs ($data, $storedata);
But then it overwrites the whole file and then puts the new entry in 🙁... I've tryed "r+" aswell and it does the same thing 🙁.
Can anyone help?
Thanks
P.S: Heres the full code for that im using for storing the data:
/* If there are errors, display the message */
if ($errors != 0)
{
print ("$errorMsg");
exit;
}
/* Check if datafile is accessable */
if (!file_exists($datafile))
{
print ("Cant access $datafile!");
exit;
}
else
{
/* Sleep for 3 secs, good flood script protection */
sleep(3);
/* If it does, open it and store the data */
$data = fopen ($datafile, "w+");
fputs ($data, $storedata);
/* Then close the file */
fclose ($data);
}