dunc453 Posted March 23, 2009 Report Share Posted March 23, 2009 Hey Any ideas why everytime someone refrshes this page after entering a comment it displays more and more of the same comment, take a look: http://www.ictkix.com/dlewis/duncan.php There is also the following error: INSERT INTO Comment VALUES (NULL,'blahj','blah','blah','blah') This is the php script: <?php echo $sql . " "; //create sql to query database //selct all records from table called: Comment $sql = "SELECT * FROM Comment"; //connect to database using username and password $dbh=mysql_connect ("localhost", "xxxxxxx", "xxxxxxx"); mysql_select_db ("dcraddoc_dlewis"); //execute sql $result=mysql_query($sql); //no. of records found $num=mysql_numrows($result); //use loop to show any records found: $i=0; while ($i < $num) { //get data from each record $id = mysql_result($result,$i,"ID"); $Email = mysql_result($result,$i,"Email"); $When = mysql_result($result,$i,"When"); $Who = mysql_result($result,$i,"Who"); $Comment = mysql_result($result,$i,"Comments"); //display on screen, in a table: echo ""; echo "$id"; echo "$Email"; echo "$When"; echo "$Who"; echo "$Comment"; echo ""; //increment value of $i to get next record (if any) $i++; } //close database connection mysql_close(); ?> Any ideas? Quote Link to comment Share on other sites More sharing options...
ll87 Posted March 23, 2009 Report Share Posted March 23, 2009 (edited) every time you refresh it resends the query and im guessing ID is auto_increment so it just creates a new record. edit: as far as solving it goes, i'm afraid im not awake enough to take a proper look (and im pretty much a beginner) Edited March 23, 2009 by ll87 Quote Link to comment Share on other sites More sharing options...
dunc453 Posted March 24, 2009 Author Report Share Posted March 24, 2009 I fixed it Did a simple redirect: if (count($_POST)) { // redirect to the same page without the POST data header("Location: ".$_SERVER['PHP_SELF']); die; } Quote Link to comment 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.
Note: Your post will require moderator approval before it will be visible.