# PHP Guestbook: change entry order

**URL:** <https://forum.kirupa.com/t/php-guestbook-change-entry-order/94084>\
**Category:** Uncategorized\
**Created:** [November 8, 2003, 7:09am UTC](https://forum.kirupa.com/t/php-guestbook-change-entry-order/94084 "2003-11-08T07:09:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![PiouPiou](https://avatars.discourse-cdn.com/v4/letter/p/a587f6/32.png) [@PiouPiou](https://forum.kirupa.com/u/PiouPiou)\
**Post date:** [November 8, 2003, 7:09am UTC](https://forum.kirupa.com/t/php-guestbook-change-entry-order/94084/1 "2003-11-08T07:09:36Z")

</div>

Hi,

I have a PHP guestbook intergrated into my flash movie, but when new entries are added they go to the bottom - I would like the newest entry to always be at the top. Can anyone please help?

Here is the PHP code:

\<?

if (!isset($name) || !isset($email) || !isset($message) || empty($name) || empty($email) || empty($message)) {  
print “&result=Fail”;  
print “&errorMsg=” . urlencode(“Input required for all fields.”);  
exit;  
}

$email = strtolower($email);

addentry($name, $email, $message);

function addentry($name, $email, $message) {

$posted = strftime("%D %I:%M %p");

$message = stripslashes($message);

$file = fopen(‘entry.txt’, ‘a+’);

if (!$file) {  
print “&result=Fail”;  
print “&errorMsg=” . urlencode(“Could not open entry.txt file. Change CHMOD levels to 766.”);  
exit;  
}

fputs($file, “\<font color=”#ffffff"\>Name:\</font\> $name  
\<font color="#ffffff"\>Email:\</font\>\<font color="#ffffff"\>\<A href=“mailto:$email”\> $email\</A\>\</font\>\<br\>  
\<font color="#ffffff"\>Posted:\</font\> $posted  
\<font color="#ffffff"\>Message:\</font\> $message

");  
fclose($file);

// Send admin an email when new entry occurs  
mailAdmin($name, $email, $message);  
}

function mailAdmin($name, $email, $message) {  
$mailTo = "you@yoursite.com";  
$mailFrom = “From: \<[you@yoursite.com](mailto:you@yoursite.com)\>”;  
$mailSubject = “New Guestbook Entry”;  
$mailBody = "A visitor to your site has left the following information in your guestbook:

```
Name: $name
Email: $email
The visitor commented:
------------------------------
$message 
------------------------------
You can view the message at:
http://www.yoursite.com";
mail($mailTo, $mailSubject, $mailBody, $mailFrom);
mail($email, "Your Subject", "Thank you message", "From: [email]you@youremail.com[/email]");

```

}

print “&result=okay”;  
exit;

?\>

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 9, 2003, 10:21pm UTC](https://forum.kirupa.com/t/php-guestbook-change-entry-order/94084/2 "2003-11-09T22:21:27Z")

</div>

thanks for your help! I actually didn’t write this code though - I don’t know PHP I can just sort of understand it when I look at it - it is just part of the guestbook I am using, so I don’t really know how to code what you suggested - would it be long and complicated or a simple statement?
