PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I am a beginner in PHP and have been given an assignment to create a guestbook in php, where the user can input comments and then be able to view all comments on a seperate page. The code I have come up with so far is as follows:
<?php
$name = $_GET['Name'];
$email = $_GET['Email'];
$comments = $_GET['Comments'];
$timedate = date("M d, Y (g:i a)", time() + 7200);
if ($name == "" or $comments == "") {
echo "One or more required fields were not completed. Please go back and try again. <br /><br />";
} else {
$oldinfo = file_get_contents("data.txt");
$guestbookdata = fopen("data.txt", "w+");
fwrite($guestbookdata, "<div class=\"post\"><strong>Name:</strong> <a href=\"mailto:{$email}\">{$name}</a> - <em>{$timedate}</em> <br />\n");
fwrite($guestbookdata, "<strong>Comments:</strong> $comments </div>\n \n");
fwrite($guestbookdata, "$oldinfo");
fclose($guestbookdata);
readfile("data.txt");
echo ("data.txt");
}
?>
I have also created a text file called data.txt that will store the data created. I'm not sure if I have done this right, I have only had 2 classes in php, so I am a bit lost with this code. We have not used MYSQL so I think the guest book has to be created without the use of it. Any help would be greatly appreciated.