Forum Moderators: coopster
[webmasterworld.com...]
Unfortunately it is too late to reply to though :o(
Anyway, here's my problem...
I have a form which reads in a date that the user selects
This is then processed on a page which generates an xml file with an automatically generated filename which includes the user ID.
This is then passed onto a calendar page, which uses the previous two pages to populate the calendar with the generated xml file. The calendar displays the current month, with the option to navigate to other months using links like <a href=\"?year=$prevYear&monthNo=$prevMonth\"> and a href=\"?year=$nextYear&monthNo=$nextMonth\">.
The problem is when you want to change the month you are viewing on the calendar the user ID is lost as it was originally posted to the page from a form, so I need a way to store this variable while users navigate throughout the months in the calendar.
I've had a crack at cookies, sessions and turning the links into forms with hidden fields but I can't get anything to work. Any help would be greatly appreciated.
Rob
Thanks for the suggestion though. Definately something to have a think about.
----------------------------------------------------
$ourFileName = "users/user".$numfiles.".xml";
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
fwrite($ourFileHandle, $finalpackage);
fclose($ourFileHandle);
echo "The XML file (ID: ".$numfiles.") has been created.";
?>
<form name="GoToCalendar" action="calendar/calendar.php" method="post" id="GoToCalendar">
<input type="hidden" name="userid" id="userid" value="<?php echo $numfiles;?>" />
<input type="submit" style="width:0px;height:0px" value="">
</form>
----------------------------------------------------
This is then automatically submitted to the next page (the calendar page), then on my calendar page I have something like
----------------------------------------------------
setcookie("chocchip", $_POST['userid']);
echo $_COOKIE["chocchip"];
// name of XML file which contains your event data
$xmlFile = "../users/user".$_COOKIE["chocchip"].".xml";
// name of header file
$headerFile = "header.inc";
// name of footer file
$footerFile = "footer.inc";
----------------------------------------------------
And this will work fine until the viewer changes month
----------------------------------------------------
// print links for previous and next months
echo "<p align=\"center\">[ <a href=\"?year=$prevYear&monthNo=$prevMonth\"><< $prevMonthName</a> ¦ <a href=\"?year=$nextYear&monthNo=$nextMonth\">$nextMonthName >></a> ]</p>\n";
----------------------------------------------------
I don't know if that made my problem any clearer?
When changing months you are using a GET request (<a href="http://www.example.com/mypage.php?name=value") which passes variables via the query string. The query string in a GET request is the "stuff" that comes after the question mark in a URI.
Since the userID is not being passed, you won't have it on the next page. You'll have to retrieve the COOKIE value to get it so you can use it.
I put an if statement in the top of my calendar page like
if (!isset($_GET['userid']))
{
$userid = $_POST['userid'];
}
else
{
$userid = $_GET['userid'];
}
and then hard coded the user ID in the change month tags like
<a href=\"?year=$nextYear&monthNo=$nextMonth&userid=$userid\">
and that seems to have fixed this problem, so thanks for your help!
Now all I have to do is figure out why I can't generate any events for the 1st of any month! The fun of programming knows no boundaries!
Anyway, thanks for your help again, I will probably be back in the forums shortly with another PHP related question!