jasonlive Posted September 20, 2013 Share Posted September 20, 2013 (edited) hey all, i am a bit lost on this one. i have a single php page it has a login form a submit new timesheet form and a display my timesheets table. this is updated as soon as the user submits a new timesheet. my issue is, after a timesheet has been submitted once, the table will add a row from the database and its great. but if i page refresh, it submits another identical timesheet. this happens even if i unset all the post variables. what is the best resolution. is there some kind of cookie i have to use? i'd rather avoid cookies. i'd also rather avoid having a second php file. i dont fully understand the $_POST variable concept. why are they not unset? Edited September 20, 2013 by jasonlive Quote Link to comment https://forums.phpfreaks.com/topic/282304-post-variable-and-page-refresh-issue/ Share on other sites More sharing options...
Solution brianlange Posted September 20, 2013 Solution Share Posted September 20, 2013 If you do a header(Location: your-html-page.php) you should be able to avoid the duplicate insert on refresh. Or if you have unique values being inserted you could do a select statement before you do the insert. Quote Link to comment https://forums.phpfreaks.com/topic/282304-post-variable-and-page-refresh-issue/#findComment-1450350 Share on other sites More sharing options...
jasonlive Posted September 20, 2013 Author Share Posted September 20, 2013 i tried the header() idea but my browser outputs an infinite loop i will attempt a better select statement Quote Link to comment https://forums.phpfreaks.com/topic/282304-post-variable-and-page-refresh-issue/#findComment-1450353 Share on other sites More sharing options...
mac_gyver Posted September 20, 2013 Share Posted September 20, 2013 the header() redirect goes inside your form processing logic so that it is only executed when there is $_POST data. Quote Link to comment https://forums.phpfreaks.com/topic/282304-post-variable-and-page-refresh-issue/#findComment-1450360 Share on other sites More sharing options...
vinny42 Posted September 20, 2013 Share Posted September 20, 2013 Or if you have unique values being inserted you could do a select statement before you do the insert. Uniqueness cannot be guaranteed that way, it can only be done by a unique constraint in the database. But in this case there is nothing that has to be unique, it's even possible that the new data must overwrite existing data. Quote Link to comment https://forums.phpfreaks.com/topic/282304-post-variable-and-page-refresh-issue/#findComment-1450362 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.