Minimeallolla Posted November 12, 2010 Share Posted November 12, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/218456-comment-refresh-glitch-mutliply-comments-need-help/ Share on other sites More sharing options...
jcbones Posted November 12, 2010 Share Posted November 12, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/218456-comment-refresh-glitch-mutliply-comments-need-help/#findComment-1133333 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.