...

View Full Version : need help with my Guestbook Script



MPCODER
01-23-2004, 10:20 AM
I've written a VERY simple guestbook script based on my request script. But i need some help with it.
Now i've posted three times "Hello World!" you can view a demo here: http://www.roelt.nl/~sentinelmods/guestlog.php post a comment and see what the problem is. I want to make it separate comments by one line and Comment:
here is the code i'm using to log comments to guestbook.php:

Thank You for posting a comment!
<?php
$file = "guestbook.php";
$comment = $_POST["comment"];

if(is_writable($file)){
$open = fopen($file,"a");
fwrite($open,$comment);
fclose($open);
}else{
chmod($file,0777) or die("Note to myself: ".$file." to 0777!");
echo 'W00ps! Something went wrong with the PHP script! Tell the staff!';
}
?>
<br>
<?php include("guestbook.php"); ?>
Here is the code i'm using for Guestbook.php:

Comment: <?php echo $_POST["comment"]; ?>
Please tell me how to separate comments.
Cheers MPCODER

raf
01-23-2004, 12:59 PM
The link is dead + i think we need to see the code where you display the comments (if i understand it correctly.

I suppose you want to have a blank line between each comment? The easiest way looks like just adding 2 breaks at the end of the comment before writing it tothe file. Like replace

$comment = $_POST["comment"];

by

$comment = $_POST["comment"] . '<br /><br />';

A cleaner way would be to add them when after you read them from the file, or to put div-tags around each comment and then define the layout inside your CSS file.

MPCODER
01-23-2004, 05:14 PM
No, i wanted to separate comments by one line and Comment:
So that if you post hello it says:
Comment: Hello

Comment: comment before it.

Taylor_1978
01-23-2004, 05:31 PM
$comment = "Comment: ". $_POST["comment"] ."<br /><br />";

MPCODER
01-23-2004, 05:46 PM
Thanks Alot Taylor! :thumbsup:

MPCODER
01-23-2004, 07:54 PM
EDIT: DON'T MIND THAT, I FOUND IT OUT MYSELF just a simple onclick="comment.value='<b>hoi</b>'">

raf
01-24-2004, 10:16 AM
Don't us clientside scripting if you can do it just as efficient with server side scripting.

There is no point in first manipulating the commentvalue clientside (which wount work and which you have no control over) and then redo or further manipulate it serversided.

MPCODER
01-24-2004, 10:36 AM
Can you help me with a server-side solution? I have a problem with smillies. I want it to log <img src="images/amused.gif"> and it logs <img src=\"images/amused.gif\"> Is there a solution for this?

MPCODER
01-24-2004, 10:53 AM
OK, i've heard something about stripslashes ($tekst) but what do i do with that? Where do i put it? I want smillies to appear in guestbook.php

Nightfire
01-24-2004, 01:49 PM
$comment = 'Comment: '. $_POST['comment'] .'<br /><br />';
//add this line below the line above
$comment = stripslashes($comment);

MPCODER
01-24-2004, 03:52 PM
It still doesn't work. Here i have my code for guestlog.php:

<?php include("guestbook.php"); ?><form name="form1" id="form1" method="post" action="guestbooktry.php">
Your Nickname:
<input name="name" type="text" id="name" />
<br />
Your Email:
<input name="email" type="text" id="email" />
<br />
Your Site:
<input name="site" type="text" id="site" value="http://" />
<br />
<input type="button" onclick="smillie.value='<b>text</b>'" value="Bold Text"><input type="button" onclick="smillie.value='<img src=&quot;images/amazed.gif&quot;>'" value=":-0" /><input type="button" onclick="smillie.value='<img src=/&quot;n//images/amuse.gif/&quot;n/>'" value=";-)"><input type="button" onclick="smillie.value='<img src=&quot;images/blink1.gif&quot;>'" value=";)"><input type="button" onclick="smillie.value='<img src=&quot;images/whip.gif&quot;>'" value=":whip:"><input type="button" onclick="smillie.value='<img src=&quot;images/mad.gif&quot;>'" value=":-(">
Smillie code
<input name="smillie" type="text" id="smillie" value="smillies" />
<br />
Your Comment:
<textarea name="comment" id="comment"></textarea>
<br />
<input type="submit" name="Submit" value="Write Guesbook" />
</form>
Here is my code for guestbooktry.php, the file that logs the comments to guestbook.php.:

<?php
$file = "guestbook.php";
$comment = "Comment: ". $_POST["comment"] ."<br /><br />";
$name = "Name: ". $_POST["name"] ."<br />";
$email = "Email: ". $_POST["email"] ."<br />";
$site = "Site: ". $_POST["site"] ."<br />";
$comment = stripslashes($comment);


if(is_writable($file)){
$open = fopen($file,"a");
fwrite($open,$name);
fwrite($open,$email);
fwrite($open,$site);
fwrite($open,$comment);
fclose($open);
}else{
chmod($file,0777) or die("Attempted to chmod the file, it was unsuccessful, please chmod ".$file." to 0777 yourself");
echo 'W00ps! Something went wrong with the PHP script! Tell the staff!';
}
?><br /> <?php include("guestbook.php"); ?> And guestbook.php is an empty file. Can you please tell me what is wrong with this?

MPCODER
01-24-2004, 06:28 PM
Someone please help me. A demo is up at http://www.roelt.nl/~sentinelmods/guestlog.php



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum