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
https://forums.phpfreaks.com/topic/164392-solved-session-variables-question/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.