chandler Posted July 13, 2011 Share Posted July 13, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/241925-php-comment-script-pls-help/ Share on other sites More sharing options...
AyKay47 Posted July 13, 2011 Share Posted July 13, 2011 why are you writing HTML to a text file? Without seeing your code, exactly where you are having issues, its hard to diagnose the problem(s)..... Quote Link to comment https://forums.phpfreaks.com/topic/241925-php-comment-script-pls-help/#findComment-1242431 Share on other sites More sharing options...
chandler Posted July 13, 2011 Author Share Posted July 13, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/241925-php-comment-script-pls-help/#findComment-1242446 Share on other sites More sharing options...
AyKay47 Posted July 13, 2011 Share Posted July 13, 2011 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>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/241925-php-comment-script-pls-help/#findComment-1242449 Share on other sites More sharing options...
chandler Posted July 13, 2011 Author Share Posted July 13, 2011 Thanks that did it Quote Link to comment https://forums.phpfreaks.com/topic/241925-php-comment-script-pls-help/#findComment-1242479 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.