Re: Guestbook - need help!

From: Date: Sun, 19 May 2002 13:18:58 +0000
Subject: Re: Guestbook - need help!
References: 1  Groups: php.mirrors 
Request: Send a blank email to php-mirrors+get-10338@lists.php.net to get a copy of this message
Sorry, but this email address is not the appropriate forum for asking support questions. For a list of more appropriate places to ask for help using PHP, please visit http://php.net/support Thank you for your interest in PHP. Goba [one webmaster@php.net] ----- Original Message ----- From: Enju To: webmaster@php.net Sent: Friday, May 17, 2002 1:17 PM Subject: Guestbook - need help! 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>&nbsp;<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

« previous php.mirrors (#10338) next »