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
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.