Jump to content

[SOLVED] Session variables question


jay0316

Recommended Posts

I'm trying to use sessions for the first time.  I am creating a multi page form.  The form will allow users to enter a quantity of a particular kit.  I have kit numbers being pulled from a database and entered as the "name" of the input fields for the quantities.

 

On the next page I start the session and I'm trying to add those quantities to the session variables.  I have the kit names in a database so I thought I'd be able to just do a while loop and have it loop through and store the values like so:

 

//start the session
session_start();

$sql = "SELECT * FROM kits";
$results = mysql_query($sql) or die(mysql_error());

while ($row = mysql_fetch_array($results)) {
$knum = $row['number'];

//register session variables
session_register('$knum');

//store posted values in the session variables
$_SESSION['$knum'] = $_POST['$knum'];
}
print $_SESSION['KCTB09'];
$test = $_POST['KCTB09'];
print "test = $test";
session_destroy();
?>

 

The $test variable works, but the session does not print anything.  However if I hard code a kit name in Session like $_SESSION['KCTB09'] = $_POST['KCTB09']; , it works.  Is it just not possible to store session values in a while loop using variables or am I doing something wrong?

 

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.