<!doctype html public "-//W3C//DTD HTML 4.0 //EN">
<html>
<head>
<title>Guestbook</title>
</head>
<body>
<table border="1">
<?php
$Name = $_POST['Guestbook_Name'];
$Email = $_POST['Guestbook_Email'];
if ($Name == "" && $Email == "")
{
echo "No user Input";
}
else{
$PostGuest = addslashes("$Name~$Email\n");
$GuestbookStore = fopen("guestbook.txt", "a");
fwrite($GuestbookStore, "$PostGuest");
fclose($GuestbookStore);
}
if (!file_exists("guestbook.txt") || filesize("guestbook.txt") == 0)
echo "<p>No guestbook Entries</p>";
else{
$GuestbookArray = file("guestbook.txt");
for ($i = 0; $i < count($GuestbookArray); ++$i){
$CurEntry = explode("~", $GuestbookArray[$i]);
echo "<tr>";
echo "<td><strong>", ($i + 1), "</strong></td>";
echo "<td><strong>Name</strong>:", stripslashes($CurEntry[0]), "<br />";
echo "<td><strong>Email</strong>:", stripslashes($CurEntry[1]), "<br />";
echo "</td></tr>";
}
}
?>
</table>
<h4>Guestbook</h4>
<form action="Week9_Chapter7.php" method="post">
<input type="text" name="Guestbook_Name" value="">
<input type="text" name="Guestbook_Email" value="">
<input type="submit" />
</form>
</body>
</html>
I want to sort the guest-book entries in alphabetical order. This is a assignment so I'm not too worried about the security at this time. I'm new to php and not too familiar what to do in this situation. I am storing the values within a text document called 'guestbook.txt'.