Jump to content

Session Problems


mister_t101

Recommended Posts

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

form
quantity
size

form
quantity
size
.
.
.


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">&nbsp;
    
    <?php
session_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]
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

[!--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
Link to comment
Share on other sites

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]


    <?php
session_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]
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.