Jump to content

passing variables using sessions - HELP


rbragg

Recommended Posts

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:
---------------
<?php
session_start();

global $cb_Unit, $cb_Pos //etc.

$_SESSION["cb_Unit"];
$_SESSION["cb_Pos"]; //etc.
?>

//start of validation using php
----------------

So, my form_result.php:
----------------
<?php
session_start();

global $cb_Unit, $cb_Pos //etc.

$_SESSION["cb_Unit"];
$_SESSION["cb_Pos"]; //etc.
?>

//start of html

<?php
$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,
Robin

Link to comment
Share on other sites

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 [code]<?php $_SESSION['var'] = $var; ?>[/code]

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

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

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

Ken
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.