Re: arrays and sessions
| From: | Justin Patrin | Date: | Sat, 28 Feb 2004 00:32:09 +0000 |
| Subject: | Re: arrays and sessions | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-179040@lists.php.net to get a copy of this message | ||
First of all, make sure you're doing session_start() before reading/writing any session data and before you do any output.
Second, You likely need to just do something like this:
session_start();
if(post data) {
$_SESSION['formArray'][] = $_POST;
}
This will save each POST array as-is in the session.
Chris W. Parker wrote:
Kermit Short <mailto:k_short@lanl.gov>-- paperCrane <Justin Patrin>on Friday, February 27, 2004 2:10 PM said:I've got some code and it simply isn't working. I thought it might be because each time the form submits data, the array I'm storing information in is being re-initialized. If this is the case, I don't have the multidimensional array I'm trying to get, but just a vector array with the most recent submission data.here are some thoughts... sounds like you're just not keeping track of each iteration. i mean, within the session variable you need to somehow differentiate between each subsequent form submittal. <?php $iteration = ++$_POST['iteration']; $_SESSION['post_data'][$iteration] = $_POST; // include $iteration in the post data // so that next time it comes around // it can be incremented. echo <<<QQQ <form method="post" action="myself"> ... <input type="hidden" name="iteration" value="$iteration" /> ... </form> ?> you should then see a multi-dimensional array with 'print_r($_SESSION);'. this code is untested and not very complete. ;) but maybe it will give you some ideas? hth, chris.