homer.favenir Posted July 30, 2009 Share Posted July 30, 2009 hi, i have a php page that submits to itself and insert the the variables to database. but everytime i refresh the page it inserts again the save variables. how can i clear the variables when i refresh the page? using a session is not an option because i want it to submit to the same page. TIA Link to comment https://forums.phpfreaks.com/topic/168132-clear-variables-when-refresh/ Share on other sites More sharing options...
rvdb86 Posted July 30, 2009 Share Posted July 30, 2009 have a look at this post: http://www.phpfreaks.com/forums/index.php/topic,139411.0.html I think they were trying to do the same as what you are aiming to do. Link to comment https://forums.phpfreaks.com/topic/168132-clear-variables-when-refresh/#findComment-886732 Share on other sites More sharing options...
TeNDoLLA Posted July 30, 2009 Share Posted July 30, 2009 Use redirect after the form is submitted and data added succesfully to db. <?php if (isset($_POST['submit'])) { // Do data validation.. // If ok, add to db. header('Location: whateverpage.php'); } Link to comment https://forums.phpfreaks.com/topic/168132-clear-variables-when-refresh/#findComment-886735 Share on other sites More sharing options...
homer.favenir Posted July 30, 2009 Author Share Posted July 30, 2009 it still getting the post variables. <?php // insert into sec_subject table $subject = $_POST['subj_check']; // get subject check box $set = $_POST['sql_trigger']; // get sql trigger if ($set == $_POST['sql_trigger']) { //query while (list ($key,$subjName) = @each ($subject)) { $exp_subj = explode("|",$subjName); $insertSql = "INSERT INTO sec_subject_tbl ( section, subject_code, subject_desc ) values ('$section','$exp_subj[0]', '$exp_subj[1]')"; echo $insertSql . "<br>"; } $set = NULL; } //close this if statement ?> Link to comment https://forums.phpfreaks.com/topic/168132-clear-variables-when-refresh/#findComment-886737 Share on other sites More sharing options...
homer.favenir Posted July 30, 2009 Author Share Posted July 30, 2009 i need to s Use redirect after the form is submitted and data added succesfully to db. <?php if (isset($_POST['submit'])) { // Do data validation.. // If ok, add to db. header('Location: whateverpage.php'); } i need to submit it to the same page.... Link to comment https://forums.phpfreaks.com/topic/168132-clear-variables-when-refresh/#findComment-886739 Share on other sites More sharing options...
TeNDoLLA Posted July 30, 2009 Share Posted July 30, 2009 Thats because you never redirect back to the page you want. Use the header() -function for that like I described earlier. And yes if you want to submit to same page you can just do the redirect to same page. Say your page is form.php where the form is located. You have action in form pointing to this particular page. Then the form processing will be done in form.php this is what you have now right? Then add after you have added data to db the header redirect to the same page also. header('Location: form.php'); And this way the script is not resending the form when refresh is pressed. Link to comment https://forums.phpfreaks.com/topic/168132-clear-variables-when-refresh/#findComment-886741 Share on other sites More sharing options...
phpSensei Posted July 30, 2009 Share Posted July 30, 2009 to ensure the header() will work, you can put this ob_start(); (very top of the pagE) and use the header to bring back the user to the same page as mentioned above, keeping the user on the page you want. or use AJAX which is probably not something your going to do. Link to comment https://forums.phpfreaks.com/topic/168132-clear-variables-when-refresh/#findComment-886742 Share on other sites More sharing options...
homer.favenir Posted July 30, 2009 Author Share Posted July 30, 2009 thanks guyz!it works but i have one problem another post variable is gone. ill try to find it myself Link to comment https://forums.phpfreaks.com/topic/168132-clear-variables-when-refresh/#findComment-886760 Share on other sites More sharing options...
phpSensei Posted July 30, 2009 Share Posted July 30, 2009 thanks guyz!it works but i have one problem another post variable is gone. ill try to find it myself print_r($_POST) see if the vars are all passing through Link to comment https://forums.phpfreaks.com/topic/168132-clear-variables-when-refresh/#findComment-886767 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.