anyway a page reload won't repost data
Moderator: General Moderators
anyway a page reload won't repost data
I have a script that inserts a record to a table based upon a user's form data(uses POST method). When they submit the form, a page loads showing the records in the table. Whenever this page is reloaded, a new record is inserted. Can this be prevented without using SQL to check for duplicate records? Is there a way to keep the page from reposting the form data?
If you cant find a way to detect attempts to add duplicate database records (examine your table's primary keys), you can try the following approach: After processing the request (and writing to the database), send a redirect to another .php page that will display the new record. Dont output anything except the from the page that writes to the database.
Code: Select all
header ('Location: http://myserver/...')can you flush the POST data
I have thought and will do it if i have to, but I guess what I really want to do is somehow flush the POST data, so the browser thinks there was no form submitted when the page is reloaded.
I'd probably do the header thing myself but this might be what you're looking for (note I didn't test it):
In your form processor script, you'll probably need an IF step before the INSERT so that you don't add empty rows to the database.
Code: Select all
<?php
function post_array_processor() {
foreach ($_POST as $key=>$value) {
$_POST[$key] = null;
}
}
?>
Last edited by McGruff on Thu Aug 11, 2005 3:03 pm, edited 1 time in total.