Staredit Network

Staredit Network -> Computers and Technical -> PHP Problem
Report, edit, etc...Posted by Pie_Sniper on 2006-01-22 at 15:58:29
Okay, I have a form with two textboxes ("name" and "comment") and a submit button. When they click the submit button, I want to call a PHP function (see image) with the values of the textboxes and reload the page. I know I could use method="get" and $_GET['...'], but I don't want to use that because then it will redo something if they refresh, and I don't want it to redo that. I made a little thing to show you what I want it like. Otherwise, if you know what I could do about the $_GET['...'] problem, that would be fine too.
Report, edit, etc...Posted by Doodle77(MM) on 2006-01-22 at 16:27:39
CODE

<HTML>
<FORM action='submit.php' method='post'>
<input type='text' name='name'><br><textarea name=comment></textarea><br>
<input type=submit>
</FORM>
</HTML>

and the php.
CODE

<?php
$comments = fopen('uicomments.txt','a+');
if (@$_POST['comment'] and @$_POST['name']) {
$comment = $_POST['comment'];
$name = $_POST['name'];
fwrite($comments, $user+":\n");
fwrite($comments,$comment+"\n");
$comments = fopen('uicomments.txt','a+');
}
rewind($comments);
while (!feof($comments)) {
echo fread($comments);
}
?>

i think thats what you were asking.
Report, edit, etc...Posted by Pie_Sniper on 2006-01-22 at 17:22:58
QUOTE
(Code boxes don't have color.)
PHP
Form

<html>

  <head>
    <title>Comment</title>
  </head>

  <body>
    <?php
      $Name = "";
      $Comment = "";
      $Read = "";
      $Write = "";
      $Filename = "Data/UIComments.txt";
      $File = "";

      function ReadComments()
      {
        global $Read, $File, $Filename;
        $File = fopen( $Filename, "r" );
        rewind( $File );
        $Read = fread( $File, filesize( $Filename ) );
        fclose( $File );
      }

      function WriteComment()
      {
        global $Read, $Write, $File, $Filename;
        $Read .= $Write;
        $File = fopen( $Filename, "w" );
        rewind( $File );
        fwrite( $File, $Read );
        fclose( $File );
      }

      if( @$_POST['name'] and @$_POST['comment'] )
      {
        $Name = $_POST['name'];
        $Comment = $_POST['comment'];
        $Write = "\n<span style=\"color: RGB( 128, 0, 128 )\"><nobr>" . $Name . "</nobr></span><span style=\"color: RGB( 192, 192, 192 )\"><nobr>:</nobr></span> " . "<span style=\"color: RGB( 0, 0, 128 )\"><nobr>" . $Comment . "</nobr></span>";
        ReadComments();
        WriteComment();
      }
      else
      {
        ReadComments();
      }
      echo "<pre style=\"font: 10pt courier new\">" . $Read . "</pre><br />";
    ?>

    <form action="UIComment.php" method="post">
      <pre style="color: RGB( 128, 0, 128 ); font: 10pt courier new">Name<span style="color: RGB( 192, 192, 192 )"><nobr>:</nobr></span>    <input type="text" name="name" value="" /></pre>
      <pre style="color: RGB( 0, 0, 128 ); font: 10pt courier new">Comment<span style="color: RGB( 192, 192, 192 )"><nobr>:</nobr></span> <input type="text" name="comment" value="" /></pre>
      <input type="submit" value="Submit" />
    </form>

  </body>

</html>

That's how my code is now. Everything works perfect, except when I submit and then refresh it says there's some POSTDATA and when I click okay it puts the message in again. So, after I've gotten the POSTDATA, is there anyway to clear the POSTDATA that keeps ( @$_POST['name'] and @$_POST['comment'] ) from evaluating to true when you refresh?
Report, edit, etc...Posted by Shmeeps on 2006-01-22 at 17:40:50
You could try

CODE

$_POST['name'] = null;
$_POST['comment'] = null;

//If null doesn't work, try "".


after doing all your PHP functions.

It may not work, as I don't know if you can manually change POST and GET variables. Give it a shot.
Report, edit, etc...Posted by RexyRex on 2006-01-22 at 17:47:39
unset($_POST); smile.gif
Report, edit, etc...Posted by Pie_Sniper on 2006-01-22 at 18:46:38
I tried that Shmeeps, it will set them but it doesn't make a difference. Same with unset(); it will unset $_POST but it still doesn't make a difference. Maybe you could suggest a better way to make a "comment system" which wouldn't have this problem?
Report, edit, etc...Posted by Doodle77(MM) on 2006-01-22 at 19:54:15
Just change it to make it check if there is an identical thing before it.
Report, edit, etc...Posted by Shmeeps on 2006-01-22 at 20:09:49
I would say take the form values, and send them to a page that enters them, then redirects back to the first page.
Report, edit, etc...Posted by Pie_Sniper on 2006-01-22 at 20:20:38
w00t you're so awesome Shmeeps. smile.gif
Report, edit, etc...Posted by Shmeeps on 2006-01-23 at 17:59:36
Hex yeah!

I believe this is how most forums do it. At least, that how the one I make is doing it.
Next Page (1)