rekha Posted February 21, 2008 Share Posted February 21, 2008 Hi, I have an HTML form that gets user info and when they press the submit button it will add the data to the database and then display the information they just added. When the user is on the confirm page, if he pushes refresh it will resubmit the data to the database. I cannot check to see if the row already exists, because it is okay for there to be multiple rows that are the same (just with a different time stamp). What is the best way to prevent this from happening? Thanks! Regards Rekha http://hiox.org Link to comment https://forums.phpfreaks.com/topic/92261-if-page-is-refreshed-data-is-written-twice-to-database/ Share on other sites More sharing options...
aschk Posted February 21, 2008 Share Posted February 21, 2008 To have an interim controller. i.e. form.html is the form process.php is the php processing, which then does a header redirect to display.html which displays the information If the user refreshes display.html no more inserts will occur (because it's just an html page). Link to comment https://forums.phpfreaks.com/topic/92261-if-page-is-refreshed-data-is-written-twice-to-database/#findComment-472637 Share on other sites More sharing options...
rekha Posted February 22, 2008 Author Share Posted February 22, 2008 Hi Thanks for your reply.But i can't understand your solution.can you please tell me in detail.I want to block the page for refresh. Regards Rekha http://hiox.org Link to comment https://forums.phpfreaks.com/topic/92261-if-page-is-refreshed-data-is-written-twice-to-database/#findComment-473450 Share on other sites More sharing options...
vicodin Posted February 22, 2008 Share Posted February 22, 2008 SO you got your page they entered the info and they press submit. All data is sent to process.php... in process.php it puts all the data from the form in the db. when its done entering it you use the header command to send them to another page that shows them the data that they entered. header function example header('Location:www.yourpage.com/showdatatheyjustentered.php') Link to comment https://forums.phpfreaks.com/topic/92261-if-page-is-refreshed-data-is-written-twice-to-database/#findComment-473457 Share on other sites More sharing options...
aschk Posted February 22, 2008 Share Posted February 22, 2008 Pretty much as vico explained ^ I suspect what you're doing at the minute is using the processing stage to display the information input. i.e. you're using a 2-stage process. You want to seperate this: e.g. form.html <form method="POST" action="process.php"> <input type="text" name="name" /> <input type="text" name="age" /> <input type="submit" name="submit" value="process me" /> </form> process.php <?php session_start(); if($_POST['submit']){ $name = $_POST['name']; $age = $_POST['age']; // Do SQL stuff like inserting into DB here. $user = array('name'=>$name, 'age'=>$name); // Store user in the session. $_SESSION['user'] = $user; } header("Location: display.php"); ?> display.php <?php session_start(); echo "name:".$_SESSION['user']['name']; echo "age:".$_SESSION['user']['age']; ?> Hope that gives you a fuller example. Link to comment https://forums.phpfreaks.com/topic/92261-if-page-is-refreshed-data-is-written-twice-to-database/#findComment-473518 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.