Shadowing Posted February 24, 2012 Share Posted February 24, 2012 anyone know how to get rid of an echo when you hit refresh on the browser? My browser is remembering the echo from with in a if statement when refresh is hit even if the if statement remains false on refresh. Quote Link to comment Share on other sites More sharing options...
trq Posted February 24, 2012 Share Posted February 24, 2012 We are going to need to see code to understand your issue. Quote Link to comment Share on other sites More sharing options...
Shadowing Posted February 24, 2012 Author Share Posted February 24, 2012 Here is a small example. if i change my email and it says "your email has been changed" If i hit refresh on the page it keeps saying it // change email if(isset($_POST['change_email'])) { if(!checkEmail($_POST['new_email'])) { echo 'Your email is not valid!'; }else{ if($_POST['new_email'] != $_POST['confirm_email']) { echo 'Your confirm email does not match your new email'; }else{ // Updates your email $update_email = "UPDATE users SET mail= '".mysql_real_escape_string($_POST['confirm_email'])."' WHERE id='".($_SESSION['user_id'])."'"; mysql_query($update_email) or die(mysql_error()); echo "Your email has been changed"; } } } Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted February 24, 2012 Share Posted February 24, 2012 You could set a $_SESSION variable. Then add a test for the variable before processing the change again. Quote Link to comment Share on other sites More sharing options...
Shadowing Posted February 24, 2012 Author Share Posted February 24, 2012 Thanks for the responce cyberRobot yah i use sessions for other things I display. then unset the session after displaying it. But wondering if i can wipe out this buffer or what ever that exist that causes this to happen Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted February 24, 2012 Share Posted February 24, 2012 This is not due to a buffer holding the output. Your code is running again every time you request the page. An alternate approach is that after you have successfully completed the form processing code, you use a header() redirect to the exact same URL that the form was submitted to. This stores a GET request in the browser's history as the last action for that URL and stops the browser from resubmitting the form data every time you refresh or browse back to that same URL. Quote Link to comment Share on other sites More sharing options...
Shadowing Posted February 24, 2012 Author Share Posted February 24, 2012 thanks for the responce PFMaBiSmAd what i dont understand is how can the code run again if the button "(isset($_POST['change_email']))" isnt pushed. if its not pushed its not isset right? or where am I off on how i thought this worked. plus the forms are empty on every refresh. So if there is no buffer then how does the form have information if the input fields are blank on each refresh? How i do my other forms i store it into a session, use a header then unset the session after its displayed. Which works fine. so i guess thats the only way to do it then. I guess i was just trying to understand why so i know exactly how its working. I need to make sure i understand this fully Also If i use a header i have to use a session other wise it wont echo at all. on page refresh 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.