Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Website GUESTBOOK 1

Status
Not open for further replies.

rastaIT34

Technical User
Sep 9, 2009
103
US
I have looked at a ton of php guest book scripts in the last few days...first of all they tell you how to install the files but none tell you how to implement it into the HTML page [ I guess they assume you already know that. ]

I tried a few and kept having issues on the server..


I am looking for a free php guestbook that has the form and the replies on the same page.... where i can put the code on my html page here:



Any thoughts?


Artist/Designer
 
Unless your webserver is set to parse the HTML files through the PHP interpreter, you won't be able to. You'll need to make your guestbook page a PHP page by changing the file extension to PHP.

Once that is done, you need to think about where you want to store the comments. Either a database or a flat file.

A flat file would be easier though you won't be able to search through the comments, and you may need to restrict the size of the comments.

Perhaps if you tell us which ones you've tried we can help you to set them up, rather than offer other scripts that you may have similar issues with.




----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
i'm trying to use:

you can see the demo here:

i tried implementing it on my site here:
i chose this guestbook because it has the form and the replies on the same page.

It has a "bad words" filter... it keeps preventing me from adding a comment...dont know why.. this one seems really complicated.... it keeps going to a index.php page.. i want to keep the look on my site...

i guess i'll keep looking...





Artist/Designer
 
I'm sorry for that last post...i installed this php script:


I dont know what I'm missing but i keep i getting this error:

Code:
Warning: fopen(gbcontentfile.php) [function.fopen]: failed to open stream: Permission denied in /home/rastaman/public_html/test/anne/guestbook/gb-exec.php on line 77

Warning: fwrite(): supplied argument is not a valid stream resource in /home/rastaman/public_html/test/anne/guestbook/gb-exec.php on line 78

Warning: fclose(): supplied argument is not a valid stream resource in /home/rastaman/public_html/test/anne/guestbook/gb-exec.php on line 79

I checked the lines its referring to, but it doesnt make any sense... any thoughts?


link:
Artist/Designer
 
Here's a straight forward one you can implement:

Copy this into a file and call it gbookfunctions.php

Code:
<?PHP
function store_comment(){
if(isset($_POST['send'])){
 $error="";
 if(!isset($_POST['guestName']) || $_POST['guestName']==""){
   $error.="<span style='color:#aa0000;'>Name is a required field to add a comment</span><br>";
   }
  if(!isset($_POST['guestEmail']) || $_POST['guestEmail']==""){
   $error.="<span style='color:#aa0000;'>Email is a required field to add a comment</span><br>";
   }
   if(!isset($_POST['guestComment']) || $_POST['guestComment']==""){
   $error.="<span style='color:#aa0000;'>Comment is a required field to add a comment</span><br>";
   }
  if($error!=""){ echo $error; return false; }
  else{
   $guestFile="comments.log";
   	 $hd=fopen($guestFile,"a+");
	 $fstr="\r\n" . $_POST['guestName'] . "|" . $_POST['guestEmail'] . "|" . htmlentities($_POST['guestComment']) . "|" . date("d/m/Y");
	 $r=fwrite($hd,$fstr);
     fclose($hd);	 
	 echo "Comment Posted"; return true;
   }
 }
}
function display_comments(){
 $guestFile="comments.log";
 if(!file_exists($guestFile)){ echo "No Comments Found"; return false; }
 $lines=file($guestFile);
 $output="";
  foreach($lines as $line){
  $comment=explode("|",$line);
    if(count($comment)==4){
	
   $output.="<div class='comment'><h2>$comment[0]<span class='date'>$comment[3]</span></h2><p>$comment[2]</p></div>";
  }
}
echo $output;
return true;
}
?>


Then in your page add this between the head tags:

HTML:
<?PHP include('gbookfunctions.php'); ?>
<style type="text/css">
.comment{
width:400px;
border:1px solid gray;
background-color:#efefef;
border-radius:6px;
margin:10px 0;
}

.comment h2{
margin-top:0;
height:30px;
line-height:30px;
font-family:Verdana;
font-size:14px;
padding-left:6px;
color:#464646;
border-bottom:2px groove #dedede;
background-color:#e6e6e6;
}

.comment h2 span{
float:right;
font-size:10px;
margin-right:6px;
color:#686868;
}

.comment p{
padding:10px;
color:#686868;
font-family:Verdana;
}

</style>

and this as your form

Code:
<?PHP 
store_comment();
?>
<div class="form">
<form action="guestbook.php" method="post">
<p><label for="gName">Name:</label><input type="text" name="guestName" id="gName"></p>
<p><label for="gEmail">Email<span>(It will not be visible)</span>:</label><input type="text" name="guestEmail" id="gEmail"></p>
<p><label for="gComment">Comment:</label><textarea name="guestComment" id="gComment"></textarea></p>
<input type="submit" value="Post Comment" name="send">
</form>
</div>
<hr>
<div id="commwrapper">
<?PHP
display_comments();
?>

It doesn't o any fancy checking or limiting though, only checks that all fields are filled in.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
I can add some spam checking features later right? that shouldnt be hard right?

i added the code and uploaded it... but the action is pointing to "guestbook.php"


where should that file be?

Artist/Designer
 
You can point it to wherever you want. If your guestbook is guestbook.php then use that if its somethingelse.php use that.

The only pre-requisite is that the PHP code is included and both functions are called as shown.

Code:
<?PHP 
store_comment();
?>
<div class="form">
<form action="[red]guestbk.php[/red]" method="post">
<p><label for="gName">Name:</label><input type="text" name="guestName" id="gName"></p>
<p><label for="gEmail">Email<span>(It will not be visible)</span>:</label><input type="text" name="guestEmail" id="gEmail"></p>
<p><label for="gComment">Comment:</label><textarea name="guestComment" id="gComment"></textarea></p>
<input type="submit" value="Post Comment" name="send">
</form>
</div>
<hr>
<div id="commwrapper">
<?PHP
display_comments();
?>

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Yes you can add to it. As far as difficulty I think that hinges on how stringent you want to be and your knowledge of PHP.





----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
just made the change but a lot of errors...


Code:
Warning: fopen(comments.log) [function.fopen]: failed to open stream: Permission denied in /home/rastaman/public_html/test/anne/gbookfunctions.php on line 17

Warning: fwrite(): supplied argument is not a valid stream resource in /home/rastaman/public_html/test/anne/gbookfunctions.php on line 19

Warning: fclose(): supplied argument is not a valid stream resource in /home/rastaman/public_html/test/anne/gbookfunctions.php on line 20
Comment Posted

Artist/Designer
 
The script seems to not have the rights to create a file there. You could try to manually create the comments.log file there.



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Fantastic! Got it working.. had to create a comment.log file and give it permissions..

you were spot on Vacunita! much thanks!

Artist/Designer
 
having made that change, you should find that the first script works too with the same fix. the error messages were all permission based. the other method is allow your web process write permissions on that directory.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top