Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
|
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 2nd, 2003, 03:00 AM
Registered User
 
Join Date: Jun 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to notChavez
Default reload/refresh problem

Howdy y'all, I've been monitoring this forum for quite a while and have managed to find answers to every question I've had already answered by Nikolai or Rich.
Thanks guys :)

My newest problem is actually a usablity issue with IE and not really a PHP problem (I'm pretty sure).

Wondering if anyone knows a way to prevent the "The page cannot be refreshed without resending the information. Click Retry to send the information again..."

I'm creating a customer/call ticketing system for my company and reloading/refreshing the page is something that happens all the time throughout the course of a day. This isn't really a show-stopper but it sure does slow down the workflow.

I'm almost positive I saw this answered already a month or more back when someone else was asking about page caching but none of my searches on the forum are returning results and Google didn't help either.

Anything anyone knows will be appreciated.

-Travis

There was a time when this was all funny to me.
 
Old December 2nd, 2003, 12:32 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That happens because the page being accessed originally had form data submitted via POST. IE (and other browsers) cache (store in memory) all the data that a user submits to ANY form during a browsing session. If the user tries to go back to a page that they submitted form data to, the browser will issue a message which basically means:

   This page was generated based on the form data that you
   submitted, so I can't refetch this page from the server
   without resending the data you submitted the first time.


One way to get around this is to use the GET method for submitting forms. All the form data is encoded in the URL for a page request, so a user that hits the back button is already resending their form data to a page since it's part of the request URL. They won't see an error message. A couple caveats, though -- there is a maximum URL length, so don't send too much data (like long strings) via GET params. Also, don't use GET to submit a form that should only be submitted once, for example, a purchase order. If a user (unwittingly) submits the same form multiple times, they'll accidentally make multiple purchases. If that's the kind of site you're building, you should have some sort of detection scheme in place that would generate a page saying "You recently completed an identical purchase -- would you like to review this recent purchase or complete a new one?", something like that.


Take care,

Nik
http://www.bigaction.org/
 
Old December 17th, 2003, 11:35 PM
Registered User
 
Join Date: Dec 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to Parisss
Default

I am having the same problem. When I go back to previous page on a game site it tells me "The page cannot be refreshed without resending the information. Click Retry to send the information again..." Unfortunately, because of the nature of the site refresh brings me different and newer info. The idea is to continue on with the information on the previous page. This did not start to occur until recently and others on the same site are not having this problem, which tells me it is not a new change in the site.

Nik: You are impressive in knowledge and resume. I believe you are a "wee bit" over my head!!! You lost me on the "One way to get around this is to use the GET method for submitting forms." I have no idea what the "GET method" is nor how to do it. Please elaborate in terms that an idiot can understand. Thanks for your time!

Parisss



Dance as if noone is watching.
 
Old December 18th, 2003, 04:08 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Using the "GET" method is as simple as changing your form method from POST to GET. That is, change this:
  <form method="post"> ... </form>

To this:
  <form method="get"> ... </form>


GET parameters are sent as part of the URL, so you can send get variables via hyperlinks. For example, look at the URL for this forum:
  http://p2p.wrox.com/topic.asp?TOPIC_ID=7107

"TOPIC_ID" is a GET parameter. In PHP, you'd access this value like this:

echo $_GET['TOPIC_ID'];

In our example, this would print "7107".


You should create a simple form with method="get" and submit it. You'll notice that all your form input fields have been encoded and appended to the URL.

For example:

<form method="get" action="http://p2p.wrox.com/topic.asp">
  Topic: <input type="text" name="TOPIC_ID" />
  <input type="submit" name="my_submit" value="Go" />
</form>

Type "7107" into the text field and submit the form. You should notice that the TOPIC_ID and my_submit variables appear after the ? in the URL.

Hope this helps clear things up!

Take care,

Nik
http://www.bigaction.org/
 
Old December 23rd, 2003, 02:03 AM
Registered User
 
Join Date: Dec 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to Parisss
Default

Spell Check
Thanks Nik for your time. I can build a computer but get lost on HTML and key commands. Is there a place, way that I can set the Get command as an option so that it is not an every time occurence to retrieve the information list on the previous page?

Also, for some odd reason the now window tends to just close now when I get the error ""the page cannot be refreshed without resending the information. Click Retry to send the information again, or click Cancel to return to the page you were trying to review." Either choice just closes that window entirely! Boy this is humbling that I can not research this one out! I have tried to find "the idiots section" Net search on this error/problem, but there does not seem to be one.

Thanks again,
Parisss



Dance as if noone is watching.
 
Old December 24th, 2003, 07:44 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm sorry but I don't quite follow what you're asking...

Quote:
quote:
Is there a place, way that I can set the Get command as an option so that it is not an every time occurence to retrieve the information list on the previous page?
Can you be a little more descriptive? I don't quite follow you.

Also, I have no idea why your window might be closing automatically.


Take care,

Nik
http://www.bigaction.org/
 
Old February 9th, 2004, 07:17 AM
Registered User
 
Join Date: Feb 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Travis

Im facing a similar problem as described by you in my JSP. After a submit, as many times i refresh the page that many duplicate entries are going in the database. I have searched the google and many of its links and unsuccessful yet...getting a cue.

I hope you would have found a workaround to this problem. Please send me a note on the know how.

Thanks
~ Nathan

Quote:
quote:Originally posted by notChavez
 Howdy y'all, I've been monitoring this forum for quite a while and have managed to find answers to every question I've had already answered by Nikolai or Rich.
Thanks guys :)

My newest problem is actually a usablity issue with IE and not really a PHP problem (I'm pretty sure).

Wondering if anyone knows a way to prevent the "The page cannot be refreshed without resending the information. Click Retry to send the information again..."

I'm creating a customer/call ticketing system for my company and reloading/refreshing the page is something that happens all the time throughout the course of a day. This isn't really a show-stopper but it sure does slow down the workflow.

I'm almost positive I saw this answered already a month or more back when someone else was asking about page caching but none of my searches on the forum are returning results and Google didn't help either.

Anything anyone knows will be appreciated.

-Travis

There was a time when this was all funny to me.
 
Old February 9th, 2004, 03:11 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, it's up to you, as the programmer, to prevent duplicate rows from being added to the database.

Someone can submit a form and refresh the target page a hundred times -- if your code just blindly accepts the user input and throws it into a database, then you will obviously get 100 duplicate rows.

You can use multiple queries and/or session variables to track whether a user has submitted a form yet or not.

For example, if a form creates a user profile with "firstName", "lastName", and "email", then simply:

<?php

if (isset($_POST['firstName']))
{
    $query = "SELECT count(*) FROM table_name
               WHERE firstname = '{$_POST['firstName']}'
                 AND lastName = '{$_POST['lastName']}'
                 AND email = '{$_POST['email']}'";

    $result = db_query($query);

    if ($result)
    {
        $count = mysql_result($result, 0);
        if ($count == 0)
        {
             // INSERT ROW HERE
        }
        // else it's already been inserted, do not duplicate.
    }
    // else there was an error with the database query.

}


}

Take care,

Nik
http://www.bigaction.org/
 
Old February 12th, 2004, 07:13 AM
Registered User
 
Join Date: Feb 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Nik... However could you please let me know... the way to handle this condition using sessions.

Thanks Again
~Nathan

Quote:
quote:Originally posted by nikolai
 Well, it's up to you, as the programmer, to prevent duplicate rows from being added to the database.

Someone can submit a form and refresh the target page a hundred times -- if your code just blindly accepts the user input and throws it into a database, then you will obviously get 100 duplicate rows.
 
Old February 12th, 2004, 06:52 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, I don't know how session data is stored in JSP. In PHP, for example, you could create a name for each form in your site, then keep track of which forms the user has submitted in their current session.

Suppose, for example, that the user has just completed a form you named "New User Form". On the page that processes the form, just check to see if the "New User Form" was submitted before processing data:

<?php
session_start();

if (isset($_SESSION['submitted_forms']['New User Form']))
{
   // user already submitted this form.

}
else
{
   // user hasn't already submitted this form.

   // process the form input here...

   // Set the session variable saying the form has been submitted:
   $_SESSION['submitted_forms']['New User Form'] = true;
}

?>


Granted, that's an oversimplification of the process -- there's arguably more than just two states (submitted vs. not submitted) that you'll want to deal with, but that's dependent on what you already have set up. It should give you enough of an idea to implement it in your current JSP site.


Take care,

Nik
http://www.bigaction.org/





Similar Threads
Thread Thread Starter Forum Replies Last Post
Reload page Tooltip not work - Reload xslt file? ismailc XSLT 10 January 22nd, 2008 10:03 AM
Problem in Reload a GridView using Timer udhayav .NET Framework 2.0 0 December 16th, 2006 07:16 AM
Problem w/ session var being incremented on reload Storm ASP.NET 1.0 and 1.1 Basics 0 October 13th, 2004 01:42 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.