Guestbook - need help!
| From: | Enju | Date: | Fri, 17 May 2002 11:17:28 +0000 |
| Subject: | Guestbook - need help! | ||
| Groups: | php.mirrors | ||
| Request: | Send a blank email to php-mirrors+get-10310@lists.php.net to get a copy of this message | ||
Hi!
Ive been trying to create this guestbook. Ive just started to learn PHP. Alla i wanted to do was to
place the latest input at the top of the page, by trying to place the content in the file
Guestbook.txt(a.k.a $filename) into the variable $content, but for some reason i cant solve, i wont
work. Could you please help me?
code:
<?php
$filename="guestbook.txt";
/*
**open file read old info
**into the variable $content
*/
if(!($myFile = fopen($filename,"r"))) {
print("Error: ");
print("'$filename' could not be read \n");
exit;
}
/*
**read a line from the file,
**repeat this until end of file
*/
while(feof($myFile)) {
$myLine = fgets($myFile,255);
$content.=$myLine;
print($content);
}
//close the file
fclose($myFile);
/*
**open file for writing
*/
if($msg == "") {
print("");
}
else {
if (!($myFile=fopen($filename,"w"))) {
print("File could not be created \n");
exit;
}
//write some lines to the file
fputs($myFile, "<tr> \n");
fputs($myFile, "<td> \n");
fputs($myFile, "<span class=\"bold\">$name</span> <br> \n");
fputs($myFile, "$visit <br> <br> \n");
fputs($myFile, "$msg <br> \n");
fputs($myFile, "$content \n");
fputs($myFile, "<hr width=\"300\" size=\"1\" noshade> \n");
fputs($myFile, "</td> \n");
fputs($myFile, "</tr> \n");
//close the file
fclose($myFile);
}
?>
</head>
<body>
<?php
/*
** open file for reading
*/
if(!($myFile = fopen($filename, "r"))) {
print("Error:");
print("'$filename' could not be read \n");
exit;
}
while(!feof($myFile)) {
//read a line from the file
$myLine = fgets($myFile, 255);
print("$myLine");
}
//close the file
fclose($myFile);
?>
</body>
</html>
----------------------------------------
/Enju