bobahad Posted December 17, 2007 Share Posted December 17, 2007 Hello guys, I created a simple entry form, but the problem is everytime I refresh the page, it keeps adding the same values over and over again. I just want it to insert it when Add is clicked. Please advice. Thanks //Query to insert in table if (isset($_POST['add'])){ $query="INSERT INTO $Table (Type,Make,Model,Year,VIN,Color,Cost,Price,Bought,Link) VALUES ('$type','$make','$model','$year','$vin','$color','$cost','$sellingprice','$datebought','$logolink')"; if(mysql_db_query($Database,$query,$Link)){ print("<FONT SIZE=\"3\" COLOR=\"Green\">"); print("The car was added successfully!\n"); print("</FONT>"); } else{ print("<FONT SIZE=\"3\" COLOR=\"Red\">"); print("The car was not added!\n"); print("</FONT>"); } //Close connection mysql_close($Link); } Quote Link to comment Share on other sites More sharing options...
kopytko Posted December 17, 2007 Share Posted December 17, 2007 Instead of <?php print("<FONT SIZE=\"3\" COLOR=\"Green\">"); print("The car was added successfully!\n"); print("</FONT>"); ?> use header function, like this: <?php header('Location: your.congrats.file'); exit; ?> When you refresh page, post is being send again, because it's made to do this, so only way to avoid this, is reload page with header function. In "your.congrats.file" you can place "The car was added successfully!" text and back link. Quote Link to comment Share on other sites More sharing options...
bobahad Posted December 17, 2007 Author Share Posted December 17, 2007 so your.congrats.file can be something like addedsuccessfully.php with a link that goes back to addcar.php ? Quote Link to comment Share on other sites More sharing options...
kopytko Posted December 18, 2007 Share Posted December 18, 2007 Yes. But remember to pass all your variables if you rely on them. Quote Link to comment Share on other sites More sharing options...
bobahad Posted December 18, 2007 Author Share Posted December 18, 2007 Thank you 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.