This is the method I recommend also. The token method works fine, but is slightly harder to implement.
Basically you would keep the function that creates the record separate from the page that shows confirmation of the record being created. e.g. 1. User visits: www.mysite.com/accounts/pages/NewInvoice.php 2. User fills out form and clicks submit, forms "Action" is: www.mysite.com/accounts/Functions/CreateInvoice.php 3. After CreateInvoice.php has successfully made the invoice, WITHOUT printing any other output, you use the header() command to send them to: www.mysite.com/accounts/pages/InvoiceSuccess.php -----Original Message----- From: Aidan Lister [mailto:[EMAIL PROTECTED] Sent: Wednesday, January 21, 2004 4:01 AM To: [EMAIL PROTECTED] Subject: Re: [PHP] Problems with $_POST Or, After you've dumped the data into the DB, issue a header('location: /path/to/script'); This will also solve the problem of IE saying "are you sure you want to resend the form data". "Toby Irmer" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > You can use a token to check if a form has been sent before... > > <? > class formReload { > > var $tokenarray = '__token'; > var $tokenname = '__token'; > > function createToken() > { > $tok = md5(uniqid("mytoken")); > return sprintf("<input type='hidden' name='%s' > value='%s'>",$this->tokenname,htmlspecialchars($tok)); > } > > function easyCheck() > { > $tok = $_REQUEST[$this->tokenname]; > if (isset($_SESSION[$this->tokenarray][$tok])) > { > return false; > } > else > { > $_SESSION[$this->tokenarray][$tok] = true; > return true; > } > } > } > ?> > > hth > > toby > > > ----- Original Message ----- > From: "Binay" <[EMAIL PROTECTED]> > To: <[EMAIL PROTECTED]>; "Reidar Solberg" <[EMAIL PROTECTED]> > Sent: Wednesday, January 21, 2004 9:23 AM > Subject: Re: [PHP] Problems with $_POST > > > Hi > > What is the primary key in your tble? Using tht primary key check for > duplicate entry... Theres no way u can change the posted data ... so even if > u reset $_POST['submit'] after the insert operation is done, next time u > refresh it will be set and hence will duplicate...so check for duplicate > entries urself only based on primary key or unique values in ur table. > > Hope this helps > > Cheers > Binay > > U wrote.. > < > I have a FORM for entering data into a DB. > > I use: > ... > ... > if ($_POST['submit'] == 'Register') { > ... > code for INSERT into DB. > > This works OK, but if I REFRESH the page, it duplicates the "dataset" in > the table. > > How can I reset $_POST['submit'] so it don't make this happen? > > Rgds > Reidar Solberg > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php