Jump to content


passing variables using sessions - HELP

  • Please log in to reply
1 reply to this topic

#1 rbragg

  • Members
  • PipPipPip
  • Advanced Member
  • 176 posts

Posted 22 June 2006 - 09:18 PM

This is my first experience using sessions for the simple fact that I'm at a new job and awaiting access to a SQL database. I'm having a heck of a time. I have a form (index.php) and submitted, the form is sent to a validation page (php_validation.php). My validation is working fine and if the information is valid, php_validation.php redirects the user to the display page for printing (form_result.php).

I do not start the session on the form page (1st page). I start it on php_validation.php like this:

global $cb_Unit, $cb_Pos //etc.

$_SESSION["cb_Pos"]; //etc.

//start of validation using php

So, my form_result.php:

global $cb_Unit, $cb_Pos //etc.

$_SESSION["cb_Pos"]; //etc.

//start of html

$cb_Unit = $HTTP_POST_VARS["cb_Unit"];
foreach ($cb_Unit as $unit) {
echo $unit."<br />";

//cont. display

Am I even close to being on the right track? Maybe I don't know how to ask the right questions. So, if there is something else you need to ask ME - feel free.

Thanks in advance,

#2 kenrbnsn

  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 22 June 2006 - 10:38 PM

No, you're not really close.

To use sessions, you need to explicitly store or retrieved stored values from the $_SESSION superglobal array.

You don't need the global statement in the main line, this statement is only used within functions when you need a value of a variable that was defined outside of the function.

When you need to store a value in a Session variable, use something like
<?php $_SESSION['var'] = $var; ?>

To use or retrieve the value, use something like
<?php $var = $_SESSION['var']; ?>
<?php echo $_SESSION['var'] ?>

Having a statment like
<?php $_SESSION['var']; ?>
is meaningless.

Also, use the $_POST superglobal array instead of $HTTP_POST_VARS.


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users