page refresh

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lmhart
Forum Newbie
Posts: 15
Joined: Tue Apr 14, 2009 1:05 pm

page refresh

Post by lmhart »

I am having issues getting a page to reload after I submit data to a database. This form should input data to a DB and then I want it to reload and list what is in database. I have gotten it to reload and list the data but it always lists everything through to the second to last entry. The most current entry does not get listed. I must refresh the page to get it to list.

main form

Code: Select all

 
<?php
include 'refresh.php'; //should refresh the page
include 'dbc.php';  //database connection
include 'list_categories.php'; //lists all the categories from the database
echo "<br />";
?>
<form name="form1" method="post" action="add_category.php">
Add Category : <input name="category" type="text" id="category"><input type="submit" name="submit" value="Submit"></p>
</form>
 
<form name="form2" method="post" action="delete_category.php">
    Delete: <?php include 'get_categories.php'; ?><input type="submit" name="submit" value="Submit">
</form>
 
<br>
    <a href="http://budget.themarkhart.com/delete_all_categories.php">Delete All</a>
 
<br>
<a href="menu.php">Menu</a>
 
refresh.php

Code: Select all

 
<?php
$page = $_SERVER['PHP_SELF'];  
header("Refresh:  url=$page");
?> 
 
list_categories.php

Code: Select all

 
<?php
 
include 'dbc.php';
 
$result = mysql_query("SELECT * FROM categories order by category ASC");
  
  while($row = mysql_fetch_array($result))
  {
     echo  $row['category'];
     echo "<br />";
   }
 
?>
 
User avatar
andym01480
Forum Contributor
Posts: 390
Joined: Wed Apr 19, 2006 5:01 pm

Re: page refresh

Post by andym01480 »

I think you need to force a fresh page download in the headers. Your browser will be using the cached page.

Code: Select all

header("Expires: ".gmdate("D, d M Y H:i:s")." GMT"); // Always expired 
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");// always modified 
header("Cache-Control: no-cache, must-revalidate");// HTTP/1.1 
header("Pragma: nocache");// HTTP/1.0
before the refresh header? (which btw I have never used!)
lmhart
Forum Newbie
Posts: 15
Joined: Tue Apr 14, 2009 1:05 pm

Re: page refresh

Post by lmhart »

andym01480 wrote:I think you need to force a fresh page download in the headers. Your browser will be using the cached page.

Code: Select all

header("Expires: ".gmdate("D, d M Y H:i:s")." GMT"); // Always expired 
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");// always modified 
header("Cache-Control: no-cache, must-revalidate");// HTTP/1.1 
header("Pragma: nocache");// HTTP/1.0
before the refresh header? (which btw I have never used!)

Thanks that was spot on!!
And I was only using the refresh.php so I could seperate the code for test purposes.
Post Reply