jay0316 Posted July 1, 2009 Share Posted July 1, 2009 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? Quote Link to comment Share on other sites More sharing options...
syed Posted July 1, 2009 Share Posted July 1, 2009 $_SESSION['$knum'] = $_POST['$knum']; remove single quotes $_SESSION[$knum] = $_POST[$knum]; Quote Link to comment Share on other sites More sharing options...
jay0316 Posted July 1, 2009 Author Share Posted July 1, 2009 That worked perfectly. Thanks! Quote Link to comment 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.