trouble with session variables...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Zooter
Forum Commoner
Posts: 45
Joined: Tue May 18, 2004 10:46 am
Location: South Africa

trouble with session variables...

Post 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) &#123; 
	document.PolicyNrSubmit.PolicyNr.value = policy_nr;
	document.PolicyNrSubmit.length.value = length;
	
	<? $_SESSION&#1111;'PolicyNr'] = $PolicyNr;
	$_SESSION&#1111;'Length'] = $length;
	$_SESSION&#1111;'IDNumber'] = $get_id; ?>
	document.PolicyNrSubmit.submit(); 

&#125; 
</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&#1111;'PolicyNr']; echo $get_policy_nr; 
$get_id = $_SESSION&#1111;'IDNumber']; echo $get_id;
 echo $_POST&#1111;'Length']. $_SESSION&#1111;'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.
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post 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";
}
??
Zooter
Forum Commoner
Posts: 45
Joined: Tue May 18, 2004 10:46 am
Location: South Africa

Post by Zooter »

Thanks. Tried it now. It says that the variable doesn't exist... But I created it?
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post 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)
Zooter
Forum Commoner
Posts: 45
Joined: Tue May 18, 2004 10:46 am
Location: South Africa

Post 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?
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post 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.
Zooter
Forum Commoner
Posts: 45
Joined: Tue May 18, 2004 10:46 am
Location: South Africa

Post by Zooter »

It give this output....

Code: Select all

208670110Array ( &#1111;Search] => &#1111;Radio] => &#1111;first_name] => Ettiene &#1111;last_name] => Grobler &#1111;email_address] => zooter@mighty.co.za &#1111;status] => &#1111;logged_in] => 1 &#1111;IDNumber] => 565 &#1111;PolicyNr] => &#1111;Length] => )
But then it is there How come it doesn't have a value??
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post 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.
Zooter
Forum Commoner
Posts: 45
Joined: Tue May 18, 2004 10:46 am
Location: South Africa

Post 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
Post Reply