jmaster85 Posted July 29, 2007 Share Posted July 29, 2007 Hi Every one , i just migrated from HELL ASP.NET to PHP and I must say that PHP RULES !! and I Love It here is my problem . i have 2 php pages , 1.php and 2.php . the 1.php simply contains a form and would be submitted to 2.php . the page 2.php then INSERTs the form data into the database . but , if the user Refreshes the page or simply back to the 2.php by BROWSER'S BACK Button , the data would Insert Again into the DB . How Can I Fix This ? here is my code the 1.php contains : <form action="2.php" method="post"> <input name="SomeString"> <input type="submit" value="send me"> </form> and the 2.php : <?php $ST = $_POST['SomeString']; $connect = new mysqli("localhost","root","","MyDB"); $connect->query("INSERT INTO MY_TABLE (ID,NAME) VALUES (NULL , '$ST'))"); ?> thanks alot Quote Link to comment Share on other sites More sharing options...
yarnold Posted July 29, 2007 Share Posted July 29, 2007 You could use sessions to record the last submit date of the form. So, when the form processes, at the top of the form add <?php session_start(); if((array_key_exists('LastPostTime', $_SESSION) && (($_SESSION['LastPostTime'] + 60) <= time()) === false) { //Process form } $_SESSION['LastPostTime'] = time(); ?> Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted July 29, 2007 Share Posted July 29, 2007 or work on a redirection. That what i do with every database submission etc. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted July 29, 2007 Share Posted July 29, 2007 also you should pre quey the table to make sure the same data isn't already there like <?php $q = "select ID From Table WHERE Message = $message"; $r = mysql_query($q) or die(mysql_error()); if(mysql_num_rows($r)){ //same message exsist } else{ insert } ?> 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.