mister_t101 Posted March 23, 2006 Share Posted March 23, 2006 I've looked everywhere in trying to help answer this question... I am trying to create a script that combines the results of several form submissions, using a 2 dimensional array. My problem is that the script doesn't seem to save the previous array, yet I know that the session function is working, because some variables are being updated. Can you create an array as a session variable? What I want to end up happening is that on array submission, the entire array is printed, including the new information.....on submission,print formquantitysizeformquantitysize...Here is the code[code]<html><body><br /><br /><table width="760" border="1"> <tr> <td width="257"><h4></h4> <form action="<?php $PHP_SELF;?>" method="post"> Pose <select name="pose"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> </select> <br> <br> Quantity <input name="quantity" type="text" value="1" size="3" maxlength="3"> <br> <br> Size <select name="size"> <option value="wallets">Wallets</option> <option value="5x7">5 x 7</option> <option value="8x10" selected>8 x 10</option> <option value="10x13">10 x 13</option> </select> <input type="hidden" name="_submit_check" value="1"/> <input type="submit"> </form></td> <td width="487"> <?phpsession_start();$_SESSION['totalBasicPoints'];$_SESSION['productNumber'];$_SESSION['order'] = array(); if (array_key_exists('_submit_check', $_POST)) {$pose = $_POST['pose'];$quantity = $_POST['quantity'];$size = $_POST['size'];$prodNum = $_POST['prodNum'];$_SESSION['product'] = array( "pose"=>$pose, "quantity"=>$quantity, "size"=>$size); array_push($_SESSION['order'], $_SESSION[product]);foreach ($_SESSION['order'] as $v){ foreach ($v as $desc){ print $desc. "<br />"; } print "<br /><br />"; } while (list($key,$value) = each($_SESSION['order'])) {echo "$key : $value<br>";while (list($value,$desc) = each($_SESSION['order'])) {echo "$key : $desc<br>";}} }?></td> </tr></table><h4><br /> <br /></h4></body></html>[/code][b]EDITED BY OBER: PLEASE USE CODE TAGS WHEN POSTING CODE. THANKS.[/b] Quote Link to comment Share on other sites More sharing options...
ober Posted March 23, 2006 Share Posted March 23, 2006 Yes, you can use arrays in session variables, however I'm not sure that you can use 2 dimensional arrays in sessions.What you should really be doing for something this complicated is setting up temporary database records. It would not only be more reliable, but it would probably be easier to work with than a bunch of multi-dimensional arrays. Quote Link to comment Share on other sites More sharing options...
keeB Posted March 23, 2006 Share Posted March 23, 2006 [!--quoteo(post=357605:date=Mar 23 2006, 02:42 PM:name=ober)--][div class=\'quotetop\']QUOTE(ober @ Mar 23 2006, 02:42 PM) [snapback]357605[/snapback][/div][div class=\'quotemain\'][!--quotec--]Yes, you can use arrays in session variables, however I'm not sure that you can use 2 dimensional arrays in sessions.What you should really be doing for something this complicated is setting up temporary database records. It would not only be more reliable, but it would probably be easier to work with than a bunch of multi-dimensional arrays.[/quote]In order to use arrays in $_SESSION variables across multiple pages, you must first [b]serialize()[/b] them for transport, and [b]unserialize()[/b] them on the next page Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted March 23, 2006 Share Posted March 23, 2006 Session variables, are autmatically serialized, you don't have to do anything except create them. Ken Quote Link to comment Share on other sites More sharing options...
mister_t101 Posted March 25, 2006 Author Share Posted March 25, 2006 after looking at [a href=\"http://www.codecomments.com/archive128-2005-1-380939.html\" target=\"_blank\"]http://www.codecomments.com/archive128-2005-1-380939.html[/a], I think i am a little bit closer to the answer; however, when I do a "print_r($_SESSION['order']);", it only prints the most recent form submission, and it doesn't seem like it's saving a new array for each form submission, or maybe I'm only asking it to tell me the most recent form submission. I don't know. The most recent code looks like this [code] <?phpsession_start();session_register('totalBasicPoints');session_register('order');session_register('productNumber');$_SESSION['totalBasicPoints'];$_SESSION['productNumber'];$_SESSION['order'] = array(); if (array_key_exists('_submit_check', $_POST)) {$pose = $_POST['pose'];$quantity = $_POST['quantity'];$size = $_POST['size'];$prodNum = $_POST['prodNum'];$_SESSION['product'] = array( "pose"=>$pose, "quantity"=>$quantity, "size"=>$size); array_push($_SESSION['order'], $_SESSION[product]);foreach ($_SESSION['order'] as $v){ foreach ($v as $desc){ print $_SESSION['order'] . ": " .$desc. "<br />"; } print "<br /><br />"; } }[/code] 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.