Page 1 of 1

Updater

Posted: Tue Jun 06, 2006 3:31 pm
by benslayton
I have 3 php pages. Index.php, add.php, and sent.php. Basically you add comments to the index.php. But thats it it adds them and I need it to replace it. You can view it here http://benslayton.awardspace.com

*index.php

Code: Select all

<html>
<head>
<title>Comment Demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<div align="center">
  <div align="left">
    <table width="80%" border="" cellspacing="0" cellpadding="0">
      <tr>
        <td align="left">
            <?php
               if ($file = @file_get_contents("comments.phpdata")) {
                echo $file."\n";
                }
            else {echo "Sorry, but no comments were found.";}
        ?>
        </td>
      </tr>
    </table>
  </div>
  <p align="left"><a href="add.php">Add Comment</a></p>
</div>
</body>
</html>
*add.php

Code: Select all

<html>
<head>
<title>Add Comment Demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<div align="center"> 
  <p><font size="+1">Add Comment Demo:</font></p>
<form name="form1" method="post" action="sent.php">
    <textarea name="comment" cols="60" rows="10"></textarea><br>
    <input type="submit" value="submit"> - <input type="reset" value="reset">
  </form>
    <a href="index.php">Back</a>
</div>
</body>
</html>

*sent.php

Code: Select all

<?php
$filename = "comments.phpdata";
if ($name = stripslashes($_POST['comment'])) {
    $comment = str_replace("<","<",$comment); //security
    $comment = str_replace(">", ">", $comment); //security 
if (strlen(@file_get_contents($filename)) > 0) $hr = "\n<hr>";
    $add = "<br>".$comment;
    $comments = @file_get_contents($filename).$add;
    $file = @fopen($filename, "w+");
    @fwrite($file, $comments);
    @fclose($file);
    $message = "Your comment was successfully added.<br>Redirecting to index.php";
    }
else {
    $message = "You either entered no data or it was entered incorrectly.<br>Redirecting to index.php";
    }
?>
<html>
<head>
<title>Comment Added Demo</title>
<meta http-equiv="refresh" content="3;url=index.php">
</head>
<body>
<div align="center"> 
<p><font size="+1">Comment Added Demo:</font></p>
<?php echo $message; ?>
</div>
</body>
</html>

please help... Thank you!! :D

Re: Updater

Posted: Tue Jun 06, 2006 3:42 pm
by PrObLeM
if you just want to overwrite the file then do this: (i think r+b is the right one.)

Code: Select all

$file = @fopen($filename, "r+b");

Posted: Tue Jun 06, 2006 3:50 pm
by benslayton
Thanks but still it doesnt work. :D

Posted: Tue Jun 06, 2006 3:53 pm
by PrObLeM
sorry, this should work now.

Code: Select all

$filename = "comments.phpdata";
if ($name = stripslashes($_POST['comment'])) {
    $comment = str_replace("<","<",$comment); //security
    $comment = str_replace(">", ">", $comment); //security

    $file = @fopen($filename, "w+");
    @fwrite($file, $comment);
    @fclose($file);
    $message = "Your comment was successfully added.<br>Redirecting to index.php";
    }
else {
    $message = "You either entered no data or it was entered incorrectly.<br>Redirecting to index.php";
    }

Posted: Tue Jun 06, 2006 4:01 pm
by benslayton
thanks that works!!!! Now since that is over with i need the text box to automatically bring the contents back from the index page. Ex. if the index page Says" This Is working" When you log onto the add page I need the text on index to come up, in the text box.

Hope thats not confusing.

Posted: Tue Jun 06, 2006 4:19 pm
by benslayton
Never mind on that 2nd question I found out how... But If you notice When I click enter on the keyboard it drops the sentence but it doesnt in the index page. Any suggestions???

Posted: Tue Jun 06, 2006 7:55 pm
by a94060
PrObLeM wrote:sorry, this should work now.

Code: Select all

$filename = "comments.phpdata";
if ($name = stripslashes($_POST['comment'])) {
    $comment = str_replace("<","<",$comment); //security
    $comment = str_replace(">", ">", $comment); //security

    $file = @fopen($filename, "w+");
    @fwrite($file, $comment);
    @fclose($file);
    $message = "Your comment was successfully added.<br>Redirecting to index.php";
    }
else {
    $message = "You either entered no data or it was entered incorrectly.<br>Redirecting to index.php";
    }
not to hijack,but for the links you use str_replace,cant you use something like htmlspecialchars() on the comment?

Posted: Tue Jun 06, 2006 10:18 pm
by benslayton
Ok that dont work. Please help me with this
I am using A WYSIWYG editor. But If I want the text bold or impact. It actually writes the code out, how do I fix that????? :D :D

Please help Very Important...

Posted: Wed Jun 07, 2006 2:21 pm
by benslayton
I figured that last post out. Now I need to know how to fix the popups, like when you click to add a color, or a hyperlink. Anyone know how?????

Posted: Wed Jun 07, 2006 2:34 pm
by a94060
what do you mean? do those popups for the color not come up or something?

Posted: Wed Jun 07, 2006 3:21 pm
by benslayton
They come up. They just dont add the color.... Or the hyperlink, or a table... etc....