Jump to content

Entrys being at the top..


zrweber

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

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

$theText = stripslashes($theMessage);

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

fwrite($data,$theMessage);
fwrite($data,$break);
fwrite($data,$break);

fclose($data);

echo "Your comment has been added!";
?>[/code]

index.php:
[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">
</form>[/code]

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..
Link to comment
https://forums.phpfreaks.com/topic/25430-entrys-being-at-the-top/
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...

[code]
<?php

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

?>
[/code]

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

Archived

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

×
×
  • Create New...

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.