Passing date as session variable to another page doesn't seem to work. I have the following code
page1
<?php
$theDate = isset($_REQUEST["date2"]) ? $_REQUEST["date2"] : "";
$_SESSION["mySessionDateVariable"] = $theDate;
$myDate=$_SESSION["mySessionDateVariable"];
?>
<div align="center">
<input name="tvar" type="text" value="<?=$myDate ?>" id="tvar" />
page2
<?php
$user=$_SESSION['MM_Username'];
$aDate = $_SESSION['mySessionDateVariable'];
?>
<body class="oneColElsCtr">
<h1><a href="http://www.frankcooley.com"><img src="images/Banner.gif" width="753" height="235" /></a></h1>
<h1>Enter a Ride for This Date</h1>
<input type="text" name="temp" value="<?=$theDate ?>" size="32" />
The first text box prints the date. the second is blank. If I substitute a string like "04-12-2008" for the mySessionDateVariable on the page1, it works in both instances. I'm only a sometime php user, so I am a little confused.
Frank
Session Variable
Moderator: General Moderators
- EverLearning
- Forum Contributor
- Posts: 282
- Joined: Sat Feb 23, 2008 3:49 am
- Location: Niš, Serbia
Re: Session Variable
You need to use session_start() in both files for sessions to work. Put it at the beggining of the file.
Code: Select all
<?php
session_start();
//rest of your code....Re: Session Variable
Thanks for the reply. Yes, I have session start in both files. Otherwise it wouldn't work with the string, which it does. If I define the variable as $_SESSION["mySessionDateVariable"] = "04-12-2008" instead of $_SESSION["mySessionDateVariable"] = $theDate; then it works. I would suspect the $theDate value, but it prints out correctly using the $myDate variable on the first page.
Frank
Frank
- EverLearning
- Forum Contributor
- Posts: 282
- Joined: Sat Feb 23, 2008 3:49 am
- Location: Niš, Serbia
Re: Session Variable
Code: Select all
$theDate = isset($_REQUEST["date2"]) ? $_REQUEST["date2"] : "";Echo the value of $theDate right after the assignement to confirm its value.
Re: Session Variable
I'm sorry, I haven't made myself clear. the code
$theDate = isset($_REQUEST["date2"]) ? $_REQUEST["date2"] : "";
$_SESSION["mySessionDateVariable"] = $theDate;
$myDate=$_SESSION["mySessionDateVariable"];
?>
<div align="center">
<form name="form1" method="POST" action="<?php echo $loginFormAction; ?>">
<input name="tvar" type="text" value="<?=$myDate ?>" id="tvar" />
on the first page does what you suggest and works correctly, indicating that $theDate does have a value and the session variable contains it. Why it doesn't get to the second page, but DOES get to the second page if it's just set as a string is what I can't fathom. I'm perfectly willing to admit that I may be overlooking something quite basic though.
Frank
$theDate = isset($_REQUEST["date2"]) ? $_REQUEST["date2"] : "";
$_SESSION["mySessionDateVariable"] = $theDate;
$myDate=$_SESSION["mySessionDateVariable"];
?>
<div align="center">
<form name="form1" method="POST" action="<?php echo $loginFormAction; ?>">
<input name="tvar" type="text" value="<?=$myDate ?>" id="tvar" />
on the first page does what you suggest and works correctly, indicating that $theDate does have a value and the session variable contains it. Why it doesn't get to the second page, but DOES get to the second page if it's just set as a string is what I can't fathom. I'm perfectly willing to admit that I may be overlooking something quite basic though.
Frank