Jump to content

[SOLVED] best way to avoid duplicate mysql entries when user clicks refresh


brianstorm

Recommended Posts

Hi,

 

I'm hoping for some guidance here as I've been messing about for too long now and as I am not entirely sure of exactly what I am trying to do I am going in circles....

 

I have a form on a php page which is used to insert data into a mysql db. The same page does the processing. At the moment clicking refresh on the browser enters the same data into the db giving a dupliacte entry.  My question is what is the best way to avoid this?

 

(The page has $_SESSION and $_POST variables currently in use)

 

If anyone cares to explain I'd be most greatful..

 

Thanks

 

 

Brian

Link to comment
Share on other sites

the best example would be:

 

main.php ->here is were the user can insert data, and on the form

                action="add.php"

 

add.php-> this page should contain the query and it will redirect to main.php after the insert

              query here....

              header('Location: main.php');

Link to comment
Share on other sites

thanks for the advice... it would seem to make data entry a bit clunky though.... if i have to redirect to a new page, and then the user has to click again to return to the form page.... is there a solution to that? can i redirect after data entry?

Link to comment
Share on other sites

ok thanks, will give that a go....

 

one last question ->> do I explicitly need to clear /reset  any $_POST variables? or $_SESSION variables? am i correct in thinking that $_POST variables will be cleared unless I pass them on, and the $_SESSION variables will continue to exist unless reset / destroyed?

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.