Jump to content

How to get rid of echo's on page refresh


Shadowing

Recommended Posts

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";
	}	
}
}

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.