Jump to content


This topic is now archived and is closed to further replies.


Entrys being at the top..

Recommended Posts

Ok I'm pretty new to PHP so I don't really know what to call everything.. But I'm using this code

$filename = "chatterbox.php";
$theText = $_POST["theMessage"];
$break = "<br>";

$theText = stripslashes($theMessage);

$data = fopen($filename, "a");



echo "Your comment has been added!";

[code]<form method="post" action="chatterboxaction.php">
<b><font face="Arial" color="#FFFFFF" size="2">Chat:</font></b><br>
<textarea name="theMessage" cols="25" rows="5"></textarea> <br>
<input type="submit" value="Post">

And what it does is let's people like say something in the form then it will add it to the page "chatterbox.php" but it adds it to the very bottom. Is there a way where when people fill out the form it adds it to the very top of the page?

Sorry if this is confusing lol..

Share this post

Link to post
Share on other sites
When you open the file using fopen() you need to specify whether it is opened for reading, writing, or both. But you can also specify whether the file pointer is at the beginning or the end of the file.

Try this...


$data = fopen($filename, "x"); //Notice I changed it from a to x


[url=http://uk2.php.net/manual/en/function.fopen.php]fopen() reference[url]

Share this post

Link to post
Share on other sites
Ok the X didn't work, I tried the other ones that start at the beginning and they would just overwrite the file.

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.