Page 1 of 1

Screen Refresh with sessions

Posted: Tue Feb 06, 2007 10:13 am
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

Posted: Tue Feb 06, 2007 11:00 am
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.

Posted: Tue Feb 06, 2007 12:24 pm
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

Posted: Tue Feb 06, 2007 5:27 pm
by feyd
Use header() to tell the browser that it must get the page data again.

Posted: Wed Feb 07, 2007 5:45 am
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

Posted: Wed Feb 07, 2007 6:14 am
by superdezign
Are your input field values coming from your database or your session?

Posted: Wed Feb 07, 2007 9:11 am
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

Posted: Wed Feb 07, 2007 2:48 pm
by SmokyBarnable
This might work.

Code: Select all

<META http-equiv="refresh" content="1;URL=<?php echo $link;?>">

Posted: Thu Feb 08, 2007 5:57 am
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

Posted: Thu Feb 08, 2007 9:33 am
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.