Code: Select all
<html>
<head>
<title>Week 5 Guestbook</title>
</head>
<body>
<h1 align="center">Please Sign Our Guestbook</h1>
<form action="thankyou.php" method="POST" name="form">
<table>
<tr>
<th>Name:</th>
<td><input type="text" maxlength="32" size="20"
name="user" id="user"></td>
</tr>
<tr>
<th>Comments:</th>
<td><textarea name="comment" cols="25" rows="7"></textarea></td>
</tr>
<tr>
<td><input type="submit" name="submitData" value="Submit Details"></td>
<td><input type="submit" name="viewComments" value="View All Comments"></td>
</tr>
</table>
</form>
</body>
</html>
Code: Select all
<?php
if(isset($_POST['submitData'] )) {
$fp = fopen("guestbook.txt", "a+");
fputs($fp, "$_POST[user]\r\n");
fputs($fp, "$_POST[comment]\r\n\r\n");
fclose($fp);
echo "<font size=18>Thank You For Visiting</font>";
}
else if (isset ($_POST['viewComments'] ))
{
function makeContent() {
$fp = fopen("guestbook.txt", "r");
if($fp) {
while(!feof($fp)) {
$row = fgets($fp, filesize("guestbook.txt"));
$bicks = preg_split("/::/", $row);
echo "<table border='1' width='100'>";
echo"<tr>";
echo "<td size=10>$row</td>";
echo "</tr>";
} fclose($fp);
}
}
echo makecontent();
}
?>