Re: [PHP] After INSERT form submit - Data doesn't refresh!



ok, in that case forget the Last-Modified or set it to the current date.


header('Last-Modified: '.gmdate('D, d M Y H:i:s', time()).' GMT');

Did you turn caching off in your browser and try it then?

Or try it with a different browser?
On Tue, Jul 22, 2008 at 2:48 PM, Rahul S. Johari <
sleepwalker@xxxxxxxxxxxxxxxx> wrote:


Here's what it is:

I have a php page, "a.php", which contains these three things:

- SELECT statement to display records from a mySQL Table
- HTML Form for inserting data into the mySQL Table
- INSERT statement to insert that row into the mySQL Table

The HTML Form submits to the same, "a.php"
Once the user submits the Form, a.php is called which INSERT's the row into
the mySQL Table. However, the row does not appear in the SELECT statement
table data unless I hit refresh on the page. (The INSERT function is
executed before the SELECT in the page).

I used the header() code that was suggested:

header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header('Pragma: no-cache');
$ffile = 'a.php';
$time = filemtime($ffile);
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $time).' GMT');

.. but it didn't help.

Everything is working fine except that the Browser is more then likely
caching the data and thus not allowing the newly inserted row to appear on
top when the SELECT is executed.


On Jul 22, 2008, at 8:34 AM, Thiago H. Pojda wrote:

Code, please? :)

On Tue, Jul 22, 2008 at 9:33 AM, Rahul S. Johari <
sleepwalker@xxxxxxxxxxxxxxxx> wrote:

Hmm, interesting.
In my case, $file does indeed output dynamic data.

I did try with the modified time but it still doesn't work. I still have
to hit refresh on the browser, after submitting the form, in order for the
inserted record to appear.

Not sure what to do - it's rather annoying. Novice users of the page would
assume the entry didn't get inserted or something happened. One alternate is
to submit Data to a different page and let that page redirect to the
Original page - but I do find it hard to believe that there is no solution
to this caching.

Thanks guys!


On Jul 22, 2008, at 8:26 AM, Yeti wrote:

The Last-Modified header tells the browser when the requested page was
last modified. Now I don't know how you get the date in your case but here
is an example:

browser requests /test/test.php which is a simple php file without any
includes etc.

in this case

$file = '/test/test.php';

This wont work if $file outputs dynamic data, so only use it if the
content only changes when you change the file.

Now if you are using templates etc. obtaining the Last-Modified time is a
bit more complicated. If you use server side caching then you can chose the
cached file else you have to figure it out yourself.

And the RFC 2616 header specification says:

An origin server MUST NOT send a Last-Modified date which is later than
the server's time of message origination. In such cases, where the
resource's last modification would indicate some time in the future, the
server MUST replace that date with the message origination date.

So do not send a future date!



On Tue, Jul 22, 2008 at 2:11 PM, Rahul S. Johari <
sleepwalker@xxxxxxxxxxxxxxxx> wrote:

I tried with just the first three header() statements you gave, but it
didn't work.
Let me try the modification date ... which file is being referred to in
$ffile?

Also, I'm using Firefox, if it's of any consequence.

Thanks!

On Jul 22, 2008, at 7:30 AM, Bernhard Kohl wrote:

I'm pretty sure this is a cache issue ..

To disable caching:
header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header('Pragma: no-cache');

But if you have the modification date then use
$time = filemtime($ffile);
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $time).' GMT');


On Tue, Jul 22, 2008 at 1:14 PM, Rahul S. Johari <
sleepwalker@xxxxxxxxxxxxxxxx> wrote:
Ave,

I'm wondering if there's a PHP solution to this, I could be in the wrong
place.
I have an INSERT form which submits to the same php page, which also
displays the records from the mySQL database the INSERT form submits to.
When the form submits and the page returns, the added record does not show
up unless you "Refresh" the page.

I'm imagining even after form submit, the Browser is caching the data and
displaying data from the Cache.

Is there a solution to this? Is there anything PHP can do to instruct the
browser not the cache the data?

Thanks!

---
Rahul Sitaram Johari
Founder, Internet Architects Group, Inc.

[Email] sleepwalker@xxxxxxxxxxxxxxxx
[Web] http://www.rahulsjohari.com





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



---
Rahul Sitaram Johari
Founder, Internet Architects Group, Inc.

[Email] sleepwalker@xxxxxxxxxxxxxxxx
[Web] http://www.rahulsjohari.com






---
Rahul Sitaram Johari
Founder, Internet Architects Group, Inc.

[Email] sleepwalker@xxxxxxxxxxxxxxxx
[Web] http://www.rahulsjohari.com







--
Thiago Henrique Pojda


---
Rahul Sitaram Johari
Founder, Internet Architects Group, Inc.

[Email] sleepwalker@xxxxxxxxxxxxxxxx
[Web] http://www.rahulsjohari.com







Relevant Pages

  • Re: [PHP] After INSERT form submit - Data doesnt refresh!
    ... SELECT statement to display records from a mySQL Table ... Everything is working fine except that the Browser is more then likely ... Rahul Sitaram Johari ...
    (php.general)
  • Packaging browser based applications for Windows
    ... I have decided to create a browser based Php application for a client/friend of mine. ... So, as a backup, I want to find the easiest way for him to be able to run the application on his home/office Windows PC. ... I am aware of XAMP and some of the other complete Windows packages, but I feel like it is too much to have him keep Apache and MySQL running all the time. ...
    (comp.lang.php)
  • Re: Changes for PHP5 ?
    ... I'm trying out my local copy of a site that uses php4, mysql,apache2. ... not use mysql are working fine though. ... So it seems that the mysql php ... Al I see in a browser is mostly a black screen, ...
    (comp.lang.php)
  • Re: Displaying a row of a table at a time - possible?
    ... > MySQL ... > The data is outputted in a table a row at a time in PHP ... > In the loop - to no avail ... browser whether or not this is even possible to do. ...
    (alt.php)
  • Re: [PHP] After INSERT form submit - Data doesnt refresh!
    ... The Last-Modified header tells the browser when the requested page was ... If you use server side caching then you can chose the ... server MUST replace that date with the message origination date. ... I'm wondering if there's a PHP solution to this, I could be in the wrong ...
    (php.general)

Loading