Page 1 of 1
trouble with session variables...
Posted: Wed May 26, 2004 9:33 am
by Zooter
a noobie problem hopefully....
I've got the one script which declares session variables in a javascript function like this.
Code: Select all
<script language= "JavaScript">
function adminClientInfoPolicy(policy_nr,length) {
document.PolicyNrSubmit.PolicyNr.value = policy_nr;
document.PolicyNrSubmit.length.value = length;
<? $_SESSIONї'PolicyNr'] = $PolicyNr;
$_SESSIONї'Length'] = $length;
$_SESSIONї'IDNumber'] = $get_id; ?>
document.PolicyNrSubmit.submit();
}
</script>
Then on the following page, I want to get these values again... Which do I use $_POST or $_SESSION? I'm doing this but it only returns the PolicyNr and the IDNumber, not the length. Where am I missing something?
Code: Select all
<?php session_start();
$get_policy_nr = $_POSTї'PolicyNr']; echo $get_policy_nr;
$get_id = $_SESSIONї'IDNumber']; echo $get_id;
echo $_POSTї'Length']. $_SESSIONї'Length'];
?>
Just a note on the side. I declare the $_SESSION['IDNumber'] in a script on a page just before the one mentioned first here. So it exists already.
Posted: Wed May 26, 2004 9:36 am
by malcolmboston
have you tried
Code: Select all
if(isset($_SESSION['something']))
{
print "the variable $_SESSION[something] is set";
}
else
{
print "this variable doesnt exist";
}
??
Posted: Wed May 26, 2004 9:39 am
by Zooter
Thanks. Tried it now. It says that the variable doesn't exist... But I created it?
Posted: Wed May 26, 2004 9:51 am
by malcolmboston
and you are definitely starting the session???
according to your script you are anyway?
on a side note have you tried printing it using $_POST (however it looks like a $_SESSION)
Posted: Wed May 26, 2004 11:25 am
by Zooter
I've substituted SESSION with POST in that code you gave me, and gave me the same result... What can cause a session variable from not being stored when posting it?
Posted: Wed May 26, 2004 11:41 am
by kettle_drum
Do a print_r($_SESSION) to just see if anything is set. Your starting the session correctly on the first page? Also not that the php is executed before the javascript will be.
Posted: Wed May 26, 2004 11:50 am
by Zooter
It give this output....
Code: Select all
208670110Array ( їSearch] => їRadio] => їfirst_name] => Ettiene їlast_name] => Grobler їemail_address] => zooter@mighty.co.za їstatus] => їlogged_in] => 1 їIDNumber] => 565 їPolicyNr] => їLength] => )
But then it is there How come it doesn't have a value??
Posted: Wed May 26, 2004 11:55 am
by kettle_drum
Well at least you know that there being posted, your just not giving them a value. Go back to where you set them, and print out what you try to assign them to.
Posted: Wed May 26, 2004 12:02 pm
by Zooter
I'll do that... Forgive me but I'm going to throw in another question here as well. If you'll look at another post I've posted, this will maybe help solve this issues as well... It is at
viewtopic.php?t=21719 .. The last 3or so posts explain what I'm trying to do. I need a number, but the leading zero's are cut off in that javascript function where I assign the value to the session variable and then submit the form. Now I've tried to convert the value to a string and also get the length of the string then, so I can then post both of those and on the next page, I can look at the length of the session variable, and if the length is shorter as the length value, I can just add as many zero's to the beginning of the string as is needed to get it long enough again. That's what I'm trying to do, but since I've tried that, this present problem happened...
But I'll just go and print out the values where I set them, maybe I'll see something obvious there...
Thanks