Screen Refresh with sessions

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
JimiH
Forum Commoner
Posts: 92
Joined: Thu Jun 15, 2006 6:10 am

Screen Refresh with sessions

Post by JimiH »

Hello

I have two input forms for users to enter data, the only difference is one posts the
Date automatically & one lets the user enter the Date manually.

The second form uses sessions to record the Date to use in a query which lets
the user know what they have entered.

Form 1

Code: Select all

include 'conn.php';
Header("Cache-control: private, no-cache");
Header("Expires: Mon, 26 Jun 1997 05:00:00 GMT");
Header("Pragma: no-cache");


echo "<table Align ='center' border='1'>";
echo "<tr> <th>Category 1</th> <th>Category 2</th><th>Time</th><th>User</th><th>Add</th>";

Form 2

Code: Select all

session_start();

include 'conn.php';
Header("Cache-control: private, no-cache");
Header("Expires: Mon, 26 Jun 1997 05:00:00 GMT");
Header("Pragma: no-cache");


echo "<table Align ='center' border='1'>";
echo "<tr> <th>Category 1</th> <th>Category 2</th><th>Time</th><th>User</th><th>Date(yyyy-mm-dd)</th>";
The problem I am having is that Form 2 requires me to manually refresh the screen before the correct data is shown (F5), Form 1 works fine.

The only difference is the session_start();

I'll include the queries for both forms

Form 1 Query

Code: Select all

$quer4=mysql_query("SELECT * From Live inner join category on cat = cat_id inner join subcategory on subcat = subcat_id WHERE Date = Current_date order by User");
Form 2 Query

Code: Select all

$Date = $_SESSION['session_var'];

Code: Select all

$quer4=mysql_query("SELECT * From Live inner join category on cat = cat_id inner join subcategory on subcat = subcat_id WHERE Date = '$Date'");
Hope this makes sense

Geoff
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Are you display information from the updated database? You have to ensure that you are getting the updated information before you are attempting to display it.

Hopefully it's that simple. I remember once (when I first started coding) I ran into a similar problem that didn't make sense, and I forced an AJAX page refresh. Hopefully you won't have to do anything as crude.
JimiH
Forum Commoner
Posts: 92
Joined: Thu Jun 15, 2006 6:10 am

Post by JimiH »

Thanks thats the problem, the updated data doesn't display until I refesh the screen using F5.

How can I force the page to update each time its loaded in PHP

Thanks

Geoff
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Use header() to tell the browser that it must get the page data again.
JimiH
Forum Commoner
Posts: 92
Joined: Thu Jun 15, 2006 6:10 am

Post by JimiH »

Hi Still cant get it to refresh after adding the header.

Code: Select all

<?php

session_start();
header("Location: http://eu-ske-sms-01/timesheet/dd5.php/"); 

include 'conn.php';
//Header("Cache-control: private, no-cache");
//Header("Expires: Mon, 26 Jun 1997 05:00:00 GMT");
//Header("Pragma: no-cache");


echo "<table Align ='center' border='1'>";
echo "<tr> <th>Category 1</th> <th>Category 2</th><th>Time</th><th>User</th><th>Date(yyyy-mm-dd)</th>";

?>
On form1 I enter text into a text box, when I click ADD the data is posted into MySQL. Then form 1 opens again
and I can see the text I entered before along with the text box if I need to enter more text. This continues until
I close the page. The problem arrises when I click the delete button next to the previously entered text. The data
is deleted from the database but still displays when I return to Form 1, hence the need to refresh the screen.

Anymore ideas?

Geoff
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Are your input field values coming from your database or your session?
JimiH
Forum Commoner
Posts: 92
Joined: Thu Jun 15, 2006 6:10 am

Post by JimiH »

In a way both, the Query which pulls the information from the DB uses a session variable. $Date, see below.

Code: Select all

$Date = $_SESSION['session_var'];
  
$quer4=mysql_query("SELECT * From Live inner join category on cat = cat_id inner join subcategory on subcat = subcat_id WHERE Date = '$Date'");
Geoff
User avatar
SmokyBarnable
Forum Contributor
Posts: 105
Joined: Wed Nov 01, 2006 5:44 pm

Post by SmokyBarnable »

This might work.

Code: Select all

<META http-equiv="refresh" content="1;URL=<?php echo $link;?>">
JimiH
Forum Commoner
Posts: 92
Joined: Thu Jun 15, 2006 6:10 am

Post by JimiH »

<META http-equiv="refresh" content="1;URL=<?php echo $link;?>">
Thanks it looks like thats the way to go, however the screen refresh's over
and over again.

How do I exit this code only once?

Thanks

Geoff
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Incorporate a URL value that your script detects as being a refresh to decide whether to exclude it or not.

header() is still preferred. .. and I'm not talking about a redirection. I'm talking about Cache-Control, Pragma, and Expires headers.
Post Reply