Forum Moderators: coopster

Message Too Old, No Replies

php mysql form insert

mysql php

         

ksugam

5:15 pm on Jun 20, 2008 (gmt 0)

10+ Year Member



Hello All,
I have a form on page 1 and after the user fills the form and hits "submit", i run a insert statement on page 2 and return the auto_increment primary key value to the user.
The issue i am facing right now is, when the user refreshes the page 2 again and again, there is a new row inserted in the database everytime because the page runs the insert statement. How can i avoid this?

Any help would be appreciated!

Thanks..

cameraman

7:04 pm on Jun 20, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There's a bunch of ways to do this, but the easiest is to do the insert on page 2 and then redirect to page 3 to display the acknowledgment or whatever to the user.

Another way is to have a creation time/date field in the table. Generate the time on page 1 as a hidden field. On page 2, check to see if a record with that creation value exists, if so, you know it's a refresh so don't do the insert.

ksugam

9:48 pm on Jun 20, 2008 (gmt 0)

10+ Year Member



I tried doing an insert on the 2nd page and use
header("Location: confirmation.php") to go on the next page.
but it is giving me an error.
"Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\saint_insert.php:5) in C:\xampp\htdocs\db_insert.php on line 51"

Can someone please help....

ksugam

10:03 pm on Jun 20, 2008 (gmt 0)

10+ Year Member



finally....i got it to work..i had included a css on page 2 which was creating the issue..
thanks for your help