Page 2 of 3
Posted: Wed Mar 24, 2004 8:38 am
by mjseaden
Yep, I understand about the cache, but the fact is on my program, if you do not fill in all details on the form, the following page checks to see if all $_POST variables contain data - if they do not, it posts a message saying to the effect 'You have not filled in all data. Click here (<-link) to return to the data form.'
If I do click on the link to the data form, the $_SESSION variables still appear empty. Is this because it is still using the cache?
Posted: Wed Mar 24, 2004 8:41 am
by magicrobotmonkey
You know, with javascript you could check before even leaving the post page...
And if you click onthe link then it will appear empty because the $_SESSION vars weren't set right?
Fill it all in and submit it, then hit back, then refresh and say yes to any questions and see what happens
Posted: Wed Mar 24, 2004 8:42 am
by mjseaden
No, the session variables are still set whether the check shows $_POST is empty of not. I did that whist trying to debug. I'll see what happens....
Posted: Wed Mar 24, 2004 8:47 am
by mjseaden
The form does not refresh with the session variables if I click 'back' then 'refresh'. No questions are asked.
At the beginning of the data form, I have a load of 'echoes' echoing the data in the session variables. At the beginning of the following page, I have a load of echoes echoing the data in the post variables, then the session variables once they have been set to their corresponding post variable (whether or not the post variable is empty or filled).
Whether I press 'back' on my browser following posting the data form contents, or go back via a link, the $_SESSION variables are empty once I go back to the data form (as shown by the aforementioned echoes) - the echoes show nothing, and therefore the contents of the form are empty.
That's the situation - and I don't understand it!
Posted: Wed Mar 24, 2004 8:50 am
by redmonkey
After pressing back and being returned to the blank form, try holding 'Shift' (or 'Control' dependant on browser) while clicking the browsers 'Refresh/Reload' icon. That should force a refresh of the page.
If you are still getting nothing then the problem would seem to point to how you are recalling the session variables.
Posted: Wed Mar 24, 2004 9:09 am
by mjseaden
Red - no joy I'm afraid. The session variables are showing themselves to be empty when I try and echo them at the beginning of the data form - and yet on the page following the data form, when I set the session variables equal to the post variables, when I echo them they show themselves to have been successfully set to the post variables.
It's only when I go back to the data form, when echoing those session variables again, that they now become empty. I have checked that I have consistently used the right labels for the session variables in the [], and I have.
It's still a problem..... :~
Posted: Wed Mar 24, 2004 9:10 am
by magicrobotmonkey
yea and change browser setting to check every time or the least caching you can
Posted: Wed Mar 24, 2004 9:15 am
by mjseaden
I don't think that the refreshing point would be the problem.
This is the sort of thing that is implemented all the time on websites that require you to fill out multi-page forms (e.g. loan/insurance/job applications). How do these people do it?
Posted: Wed Mar 24, 2004 9:18 am
by magicrobotmonkey
From what you are saying, you have the right idea of how to implement it, because its not too hard, I think you have it right its got to be something with settings or something unless you are not telling us something
Posted: Wed Mar 24, 2004 9:21 am
by redmonkey
So it's not looking like a cache problem, can we see your code for the two pages, it seems that the session variables are either not being set or not being recalled correctly.
Posted: Wed Mar 24, 2004 9:42 am
by mjseaden
Okay, I'll just get the code together and post it
Posted: Wed Mar 24, 2004 10:04 am
by mjseaden
Add item - this displays the data form, and submits via posting variables as usual.
Code: Select all
// additem()
// Adds an item to the database
function additem()
{
// We need to start a session to check that they are already logged in, and obtain the session variables
// if they have been set so that the form can be filled with the correct information
session_start();
// Check that they are a valid user. If a user attempts to access this page without logging in they will be rejected here
check_valid_user();
// Now get the logged in username
$user = $_SESSION['valid_user'];
do_html_header('Add Item', TRUE);
do_html_title('<STRONG>Add Item to Database</STRONG>');
echo $_SESSION['item_ID'];
// others echoed here
// HTML form
?>
<FORM METHOD="post" NAME="myForm" ACTION="run2.php?p=24" STYLE="margin: 0px">
<TABLE CELLPADDING="0" CELLSPACING="0" BORDER="0">
<TABLE CELLPADDING="0" CELLSPACING="0" BORDER="0">
<TR>
<TD HEIGHT="20" WIDTH="718" STYLE="padding-left:16px;padding-right:16px" BGCOLOR="#000066"><FONT COLOR="#FFFFFF" FACE="Tahoma" SIZE="2">
Please enter new item details below. A key is given to describe the various data entries. You may cancel at any time by clicking the 'Back' button on your browser.
</FONT></TD>
</TR>
<TR>
<TD HEIGHT="10" WIDTH="718" STYLE="padding-left:16px;padding-right:16px" BGCOLOR="#000066"><FONT COLOR="#FFFFFF" FACE="Tahoma" SIZE="2">
</FONT></TD>
</TR>
</TABLE>
<TABLE CELLPADDING="0" CELLSPACING="0" BORDER="0">
<TR>
<TD HEIGHT="20" WIDTH="114" STYLE="padding-left:16px" BGCOLOR="#000066"><FONT FACE="Tahoma" SIZE="2" COLOR="#FFFFFF">
ID Number
</FONT></TD>
<TD HEIGHT="20" WIDTH="604" STYLE="padding-right:16px" BGCOLOR="#000066"><FONT FACE="Tahoma" SIZE="2" COLOR="#FFFFFF">
<?php
if(isset($_SESSION['item_ID'])) echo '<INPUT TYPE="text" LENGTH="100" SIZE="26" NAME="txt_ItemID" VALUE="'.$_SESSION['item_ID'].'">';
else echo '<INPUT TYPE="text" LENGTH="100" SIZE="26" NAME="txt_ItemID">';
echo ' e.g. DE-10-157';
?>
</FONT></TD>
</TR>
</TABLE>
<TABLE CELLPADDING="0" CELLSPACING="0" BORDER="0">
<TR>
<TD HEIGHT="8" WIDTH="734" STYLE="padding-left:16px" BGCOLOR="#000066"></TD>
</TR>
</TABLE>
// Various other text controls, which use exactly the same populating method as the one above
<TABLE CELLPADDING="0" CELLSPACING="0" BORDER="0">
<TR>
<TD HEIGHT="8" WIDTH="750" BGCOLOR="#000066"></TD>
</TR>
</TABLE>
<TABLE CELLPADDING="0" CELLSPACING="0" BORDER="0">
<TR>
<TD WIDTH="419" STYLE="padding-left:16px" BGCOLOR="#000066" ALIGN="LEFT"><INPUT TYPE="reset" VALUE="Reset" NAME="reset"></TD>
<TD WIDTH="300" STYLE="padding-right:15px" BGCOLOR="#000066" ALIGN="RIGHT"><INPUT TYPE="submit" VALUE="Next >>" NAME="next"></TD>
</TR>
</TABLE>
<TABLE CELLPADDING="0" CELLSPACING="0" BORDER="0">
<TR>
<TD HEIGHT="5" WIDTH="750" BGCOLOR="#000066">
</TD>
</TR>
</TABLE>
</TABLE>
</FORM>
<?php
do_html_footer();
}
Then this is the code for the following page, which successfully receives the posted variables:
Code: Select all
function addphotos()
{
// Start a session if not already started in order to save the previous data form contents and
// forward to next page for preview
session_start();
// Check for valid login
check_valid_user();
// Now set the session variables so the data form will still be filled in on pressing 'back'
echo $_POST['txt_ItemID'];
// Other variables are displayed here but I have censored them because it is a simple repetition
$_SESSION['item_ID'] = $_POST['txt_ItemID'];
// Other session variables set here, but same method is used
// Now print them to see if they are set properly
echo '<BR>'.$_SESSION['item_ID'];
// --> and they are!
if($_POST['txt_ItemID'] == "")
{
do_html_header('Data Missing', FALSE);
do_html_title('<STRONG>Please Fill In All Data</STRONG>');
do_html_message('You have not filled in all data on the item data form. Please click <A HREF="xxxx.php?p=22"><FONT COLOR="#000000">here</FONT></A> to return to the data form (do not press ''back'' on your browser).');
do_html_footer();
exit();
}
// All other variables checked in the same way
// Other code was placed here but it is only relevant to this page and does not interfere with the variables
do_html_header('Upload Photographs', FALSE);
do_html_title('<STRONG>Upload Photographs to Database</STRONG>');
?>
}
// That's it
Thanks for your help.
Posted: Wed Mar 24, 2004 10:26 am
by mjseaden
/bump
Posted: Wed Mar 24, 2004 10:51 am
by redmonkey
mjseaden wrote:/bump
Please note, I'm not just sitting here waiting to help you! bumping a thread only 20 minutes after your last post will just annoy people and most likely result in being ignored in the future.
Now, I don't see anything obviously wrong but I would suggest that you try a simple test first to ensure that session variables are being passed from page to page. Simply setting a session variable and then immediately echoing it back out does not show that the session variable is being stroed correctly.
Try a simple test without all the function calls and login checks and see what happens. This way you can determine if the problem is code related or server related.
Here are two pages which create a basic implemtation of what you are trying to do... Take these two pages and run them and see if works or not.
page1.php
Code: Select all
<?php
session_start();
$item1_ID = isset($_SESSION['item1_ID']) ? $_SESSION['item1_ID'] : '';
$item2_ID = isset($_SESSION['item2_ID']) ? $_SESSION['item2_ID'] : '';
?>
<html>
<body>
<form method="post" action="page2.php">
<table>
<tr>
<td>Item 1</td>
<td>
<input type="text" length="100" size="26" name="txt_item1ID" value="<?php echo $item1_ID ?>">
</td>
</tr>
<tr>
<td>Item 2</td>
<td>
<input type="text" length="100" size="26" name="txt_item2ID" value="<?php echo $item2_ID ?>">
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" name="submit" value="Submit">
</td>
</tr>
</table>
</form>
</body>
</html>
page2.php
Code: Select all
<?php
session_start();
if (isset($_POST['txt_item1ID']))
{
$_SESSION['item1_ID'] = $_POST['txt_item1ID'];
if (!empty($_POST['txt_item1ID']))
{
$item1_ID = true;
}
}
if (isset($_POST['txt_item2ID']))
{
$_SESSION['item2_ID'] = $_POST['txt_item2ID'];
if (!empty($_POST['txt_item2ID']))
{
$item2_ID = true;
}
}
if (!isset($item1_ID) || !isset($item2_ID))
{
?>
<html>
<body>
All fields are required go <a href="page1.php">back</a> to complete the form.
</body>
</html>
<?php
}
else
{
?>
<html>
<body>
All fields are set
</body>
</html>
<?php
}
?>
Posted: Wed Mar 24, 2004 10:57 am
by mjseaden
Hi red
Thanks for your post. Your code does work on my system - there must be some sort of problem with my code. I'll take another look through it and compare to your method.
Thank very much
Mark