Page 1 of 1

reply to an entry

Posted: Sun Aug 28, 2005 5:39 pm
by ivan
Script URL: localhost
Version of script: 1.33
Version of PHP: 5.0.4
Hosting company: none
Have you searched THIS FORUM for your problem: i did
(if not please do before posting)
If so, what terms did you try:

Write your message below:



Hi.. First of all, thanks you very much for your worderfull script.
I tried to add more entries at the end of the specific line (it's a reply to a specific post in my guestbook). But each time I submit this entry, it will add replies to each entry in my guestbook, instead posted in a single entry.
A part of my (uhmm, yours actually ;)) is here:

Code: Select all

<?
// -------------------------------------function insert reply -----------------------------------------
function doAddResp($pass,$num) {
global $settings;
$add = gbook_input($_REQUEST['add']);
$num = gbook_input($_REQUEST['num']);

// spell check
$delimiter="\t";
$addedrep = date ("l, M jS Y H:i");
$add = str_replace("\r\n","<br />",$add);
$add = str_replace("\n","<br />",$add);
$add = str_replace("\r","<br />",$add);
$add = wordwrap($add,$settings['max_word'],'<br />',1);
if ($settings['smileys'] == 1 && $_REQUEST['nosmileys'] != "Y") {$add = processsmileys($add);}
if ($settings['filter']) {
	$add = filter_bad_words($add);
}
// add this entries before \n
$repline = "$delimiter$add$delimiter$addedrep$settings[newline]";

// read entries
$fp = @fopen($settings['logfile'],"rb") or problem("blah blah");
$reply = @fread($fp,filesize($settings['logfile']));
fclose($fp);

// write entries <<-- this is where things get complicated for me
$lines = explode($settings['newline'],$reply);
$fp = fopen($settings['logfile'],"wb") or problem("blah blah");
foreach ($lines as $thisline) {
$thisline .= $repline;
fputs($fp,$thisline);
}
fclose($fp);
// fin function insert reply 
?>
I have an online version of this script at http://fsight-team.com/guestbook.php. This is what the script intended to look like. Note that replied post there was done manually editing the entries.txt.

I'm a newby to PHP. Are there any solution to this? :roll:

Posted: Sun Aug 28, 2005 8:40 pm
by ivan
I might not clearly explain my case..
I will try to explain what i'm doing with this..

first i put a link in every guestbook post

Code: Select all

<a href=\"guestbook.php?a=addresp&num=$i\">Reply to this post</a>
this hyperlink will pull out some condition stated in if (!(empty($a))) {

Code: Select all

	elseif($a=="addresp") {
		$num=gbook_isNumber($_REQUEST['num'],"Invalid ID");
  		confirmAddResp($num);
	}
and then displaying a confirmation page with password (similar to deleting a post), because this "reply" needed administrator previlidge

Code: Select all

function confirmAddResp($num) {
?>
<br /><br />
<br /><br />
<form action="guestbook.php" method="post"><input type="hidden" name="a" value="addresponse" />
addresponse passed variable password and will pull another condition in if (!(empty($a))) {

Code: Select all

	elseif($a=="addresponse") {
		$pass=gbook_input($_REQUEST['pass'],"Please enter your password");
        	$num=gbook_isNumber($_REQUEST['num'],"Invalid ID");
	   	AddResponse($pass,$num);
	}
and will bring me to a form

Code: Select all

// --------------------------------------------add reply ----------------------------------------
function AddResponse($pass,$num) {
global $settings;
if ($pass != $settings[apass]) {problem("Wrong password! Only the guestbook owner may read this post!","1");}

$delimiter="\t";
$lines = file($settings['logfile']);
list($ipaddr,$name,$from,$str,$url,$comments,$added,$isprivate)=explode($delimiter,$lines[$num]);
echo "<br /><br />";

echo "
	on $added <b>$name</b> wrote:<br /><br />
	$comments<br /><br />";
echo "Post Reply:";?>
<form action="guestbook.php" method="post">
<input type="hidden" name="a" value="addentresp" />
<input type="hidden" name="pass" value="<?php echo ($pass);?>" /> 
<input type="hidden" name="num" value="<?php echo($num); ?>" />
<textarea name="add" rows="9" cols="50"></textarea><br />
<input type="submit" value=" Post Reply " />
</form>
<?

printCopyHTML();
printDownHTML();
exit();
}
// END AddResponse
go back to if (!(empty($a))) {

Code: Select all

	elseif($a=="addentresp") {
		$add=gbook_input($_REQUEST['add'],"Please enter your Reply");
		doAddResp($addentresp,$addedrep);
	}
and the last code is the code i provide in my first post.. Can somebody show me what's wrong with this?
The script works pretty, unless what i mention above. I suspect i made a mistake in my first post, but i don't know where. Your respons very much appreciated..

Posted: Sun Aug 28, 2005 8:46 pm
by ivan
My bad :oops:.. wrong code in my post above.. should be:

Code: Select all

	elseif($a=="addentresp") {
		doAddResp($pass,$num);
	}