Jump to content

Recommended Posts

Hi I think this should be an easy one for you lot

 

$fp = fopen('messages.txt', 'a');
fwrite($fp, "<div id=\"census41_messages\"><p>$message<br />$message2</p></div>");
fclose($fp);

 

The  div above is the problem, this is wrote to the file each time a comment is made and is messing up the layout of the comments, how can I get the div to go around all the comments?.

 

 

Thanks for your help.

 

Link to comment
https://forums.phpfreaks.com/topic/241925-php-comment-script-pls-help/
Share on other sites

Here is the full script, all I want to be able to do is to style the comments, but if I have "<div id=\"census41_messages\">" where it is now, then I have this result

<div id="census41_messages"> <p>Name<br />Message</p></div>

<div id="census41_messages"> <p>Name<br />Message</p></div>

<div id="census41_messages"> <p>Name<br />Message</p></div>

 

but what I want is!

<div id="census41_messages">

<p>Name<br />Message</p>

<p>Name<br />Message</p>

<p>Name<br />Message</p>

</div>

 

		<?php

if (isset($_POST['message']))
{
if (isset($_SESSION['token']) && $_POST['token'] == $_SESSION['token'])
{
$message = htmlentities($_POST['message']);
$message2 = htmlentities($_POST['message2']);

$fp = fopen('messages.txt', 'a');
fwrite($fp, "<div id=\"census41_messages\"> <p>$message<br />$message2</p></div>");
fclose($fp);
}
}

$token = md5(uniqid(rand(), true));
$_SESSION['token'] = $token;

?>


<form id="contFrm" method="POST">
<input type="hidden" name="token" value="<?php echo $token;?>" />
<label><span class="required">*</span> Full Name:</label>
<input type="text" class="box"  name="message"><br />
<label><span class="required">*</span> Message: </label>
<textarea name="message2" id="message" cols="25" rows="8"></textarea><br />
<input type="submit" class="button" value="Submit">
</form> 




<?php
readfile('messages.txt');
?> 

 

 

Thanks

why don't you echo the beginning an ending parts of the div, and make the middle dynamic

 

		<?php

if (isset($_POST['message']))
{
if (isset($_SESSION['token']) && $_POST['token'] == $_SESSION['token'])
{
$message = htmlentities($_POST['message']);
$message2 = htmlentities($_POST['message2']);

$fp = fopen('messages.txt', 'a');
fwrite($fp, "<p>$message<br />$message2</p>");
fclose($fp);
}
}

$token = md5(uniqid(rand(), true));
$_SESSION['token'] = $token;

?>


<form id="contFrm" method="POST">
<input type="hidden" name="token" value="<?php echo $token;?>" />
<label><span class="required">*</span> Full Name:</label>
<input type="text" class="box"  name="message"><br />
<label><span class="required">*</span> Message: </label>
<textarea name="message2" id="message" cols="25" rows="8"></textarea><br />
<input type="submit" class="button" value="Submit">
</form> 




<?php
echo "<div id=\"census41_messages\"> ";
readfile('messages.txt');
echo "</div>";
?> 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.