943,169 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 1175
  • PHP RSS
Aug 31st, 2010
0

How to stop sending data on refresh

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
designer_shiv is offline Offline
9 posts
since Jun 2010
Aug 31st, 2010
0
Re: How to stop sending data on refresh
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.
Reputation Points: 11
Solved Threads: 5
Light Poster
EverWebby is offline Offline
46 posts
since Jan 2010
Sep 1st, 2010
0
Re: How to stop sending data on refresh
Always try to practice with header.
PHP Syntax (Toggle Plain Text)
  1. <?
  2. if(isset($_REQUEST['submit']))
  3. {
  4. /* ----------
  5. your code
  6. ------------ */
  7. header("Location:page.php");
  8. exit;
  9. }
  10. ?>
Because if there is no header and you press refresh then form will be resubmitted.
Reputation Points: 154
Solved Threads: 162
Master Poster
vibhadevit is offline Offline
791 posts
since Apr 2010
Sep 1st, 2010
0
Re: How to stop sending data on refresh
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:
PHP Syntax (Toggle Plain Text)
  1. header("location:http://www.mywebsite.com/index.php");
  2. exit;

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

Hope it helps :-)
Last edited by sithembisophp; Sep 1st, 2010 at 3:33 am.
Reputation Points: 10
Solved Threads: 3
Newbie Poster
sithembisophp is offline Offline
14 posts
since Aug 2010
Sep 2nd, 2010
0

Thanks

Thank you for your suggestion,
Reputation Points: 10
Solved Threads: 0
Newbie Poster
designer_shiv is offline Offline
9 posts
since Jun 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Looking for help on output rows in a table
Next Thread in PHP Forum Timeline: Can't override the __doRequest function from the SoapClient class





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC