PHP/SQL -> Duplicate data on Insert when Page is refreshed
-
Hi guys., am having with duplicate entry on the DB when the Page is refreshed.. any solution please,. what am trying to do is when the data is added, the portion of the page loads, not the whole page, am using AJAX to load potion of the page.. help guys, thanks..
-
Hi guys., am having with duplicate entry on the DB when the Page is refreshed.. any solution please,. what am trying to do is when the data is added, the portion of the page loads, not the whole page, am using AJAX to load potion of the page.. help guys, thanks..
-
Hi guys., am having with duplicate entry on the DB when the Page is refreshed.. any solution please,. what am trying to do is when the data is added, the portion of the page loads, not the whole page, am using AJAX to load potion of the page.. help guys, thanks..
A refresh will resubmit $_POST variables, that if you are using them in your page logic, means the logic will repeat. These values are stored on the users browser so using unset to clear the post variable will do you no good, you need to do 2 things the first is as the other poster says, make certain the information does not already exist. The second is when the data is processed send the user to a specific URL. This will keep the user from refreshing the page and having post vars repeated. On a side note if you are echoing any information before you redirect the user, they will get a error message (headers already sent or some such). You can fix this with eith redirect by using javascript or you can redign your code to put all the echo'd information into a variable and echo that just after you redirection code.
-
Hi guys., am having with duplicate entry on the DB when the Page is refreshed.. any solution please,. what am trying to do is when the data is added, the portion of the page loads, not the whole page, am using AJAX to load potion of the page.. help guys, thanks..
I assume you are using an ajax framework which uses iframe to submit your form. In that case you are doing a normal refresh like you press F5. Or if you say that you are using javascript to reload the page like window.location.reload() then you will face that problem whether you are using F5 or reload using javascript. whatever. use window.location.href = window.location.href. this is like assigning a string to as the new url instead of meaning to the browser as reload. so the browser will load the page as a new request instead of page refresh. so we are reassigning a new(same) url (requesting the browser to load that page) instead of requesting the browser to reload the page. so the only difference here is loading a page and reloading a page. To load a page use window.location.href = window.location.href (new request) To reload a page use window.location.reload(). (refresh the same) I suppose that your problem lies within this. If you are not using ajax then use the redirect option in php to the same controller(page) to change the last loaded url. for example if you are posting your form data to a page called post.php in that after processing the database operation redirect to again the same post.php. by doing so you are changing the last request as a get request. and after that when you refresh the browser will issue a get request and not the previous post request because it will do a reload only with the last request. DO YOU NEED A SAMPLE CODE? IF THIS DID NOT SOLVE YOUR PROBLEM THEN USE INSERT IGNORE INTO table (field1,field2) VALUES(1,2); Better i should blog this answer with more possible combination. :-\
Today's Beautiful Moments are Tomorrow's Beautiful Memories