rbragg Posted June 22, 2006 Share Posted June 22, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/12676-passing-variables-using-sessions-help/ Share on other sites More sharing options...
kenrbnsn Posted June 22, 2006 Share Posted June 22, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/12676-passing-variables-using-sessions-help/#findComment-48633 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.