HI All

I am relatively new to PHP and am in the processing of developing a site making use of PHP and MySQL. The problem I am experiencing is that when I refresh Internet Explorer, the data that was processed by a form is resubmitted to the database - can anyone tell me what the correct process is to avoid having this happen. The only thing that comes to mind is to, after the processing is complete, redirect to another screen - ultimately I would like to avoid doing that.

Any ideas?

Thanks in advance

Shiv

Recommended Answers

All 4 Replies

You might want to implement a session token or javascript redirect. A session token gets implemented before page execution and on page execution it gets destroyed. And the javascript way has its obvious implementations. Also, your database could assist in this if you are inserting the unique value which to compare against.

Always try to practice with header.

<?
	if(isset($_REQUEST['submit']))
	{
		/* ----------
		   your code 
		 ------------ */
		 header("Location:page.php");
		 exit;
	}
?>

Because if there is no header and you press refresh then form will be resubmitted.

You are absolutely right EverWebby. I have encountered the same problem before and I made use of the following options:

1. I was storing a unique ID in the mysql database and what I did is that if the page is refreshed, I would check on the database if this ID has been recorded before. If so I then redirected the user to another page. But Mysql queries are expensive to make, so I will encourage you to use redirection where possible:

2. To implement redirection in PHP you user:

header("location:http://www.mywebsite.com/index.php");
exit;

In this case I redirect the user to my default index.php page.

Hope it helps :-)

Thank you for your suggestion,

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.