Jump to content

Duplicate SQL entry when refreshing browser


syl_kn

Recommended Posts

Hi all,

 

I'm quite new to PHP and SQL, I've searched the forums for an answer to this but can't find anything that quite fits.

 

I have a simple page which inserts usernames, dates...etc into a database, but when the page is refreshed the last entry is re-inserted into the database. How can I stop this?  Is there a simple way?

 

Any help will be appreciated.

 

Thanks.

 

Link to comment
Share on other sites

Well I did not clearly understood the problem. When you click the refresh of course it will insert newly to the database as the whole page is running again. And I don't think there is a way to stop it. Browsers mostly notify you when you click on refresh that post data will be send again. Maybe HTTP_REFERRER can be used. If the referring page is the form page then insert or if the referrer is itself, I'm not sure if you click on refresh that referrer will change, do not insert.

I assume that it inserts a data with duplicate user like two 'john' which will cause a possible password conflict. A solution is that you could put a unique key to your username. By this way there is no way to insert two 'john's as it will violate the unique key constraint. Another way is to check this via php or another programming lanugage manually. First "select * from users where username='jhon'" and if the result rows are higher then zero, then show an error that this name is already inserted and the user should choose another name.

Link to comment
Share on other sites

Hi all,

 

I'm quite new to PHP and SQL, I've searched the forums for an answer to this but can't find anything that quite fits.

 

I have a simple page which inserts usernames, dates...etc into a database, but when the page is refreshed the last entry is re-inserted into the database. How can I stop this?  Is there a simple way?

 

Any help will be appreciated.

 

Thanks.

 

 

Easy way is just to use an http redirect without the POST data.

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.