Jump to content

comment refresh glitch. mutliply comments need help!


Minimeallolla

Recommended Posts

when i comment and reresh it resends the comment so i have done 2 comments and continues if i keep refreshing and just multiplies. how can i stop the fetch or while loop.

<?php 
  $query = ("SELECT * FROM homecomments");
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result))
{
echo "<b>";
echo $row['username'] . "</b>: <Br> ";
   echo htmlentities($row['comment'], ENT_QUOTES, "UTF-8");
echo "<p>";
}
?>

thats my echo comment code. would it ahve anything to do with that?

Refresh sends the data back to the page again.  That is why you get a pop up that ask "do you wish to resend the data". or thereabouts.

 

Three things you can do.

 

1. Re-direct the page to itself after the database insertion.  This clears the data out of the headers, so on refresh it will not send the data back to the page.

 

2. Set a session variable that limits the amount of time between comments. This agitates the user, and they usually don't sit there and wait for the timer to run out.

 

3. Check the comment against the last one the user supplied to the database, if it is the same, deny it.  This creates and extra query to the database.

 

The first one is the most logical, although it creates more server load.  On a system that isn't seeing 100's of pages an hour, it is no big deal.  This is the way that dreamweaver deals with the problem.

 

And no, the echo loop has nothing to do with it.  It is the insertion code you are dealing with.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.