syl_kn Posted August 24, 2007 Share Posted August 24, 2007 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. Quote Link to comment Share on other sites More sharing options...
Illusion Posted August 24, 2007 Share Posted August 24, 2007 yes u can stop this by having a primary key in ur table. Quote Link to comment Share on other sites More sharing options...
radalin Posted August 24, 2007 Share Posted August 24, 2007 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. Quote Link to comment Share on other sites More sharing options...
fenway Posted August 27, 2007 Share Posted August 27, 2007 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.