/    Sign up×
Community /Pin to ProfileBookmark

$_SESSION array?

Hi,

Ok, i know that by using this

[code=php]
$_SESSION = array_merge($_SESSION, $_POST);
[/code]

I am putting all the post variable into a single session.

Now, my question is

How can i then add to that. For example: –

i have 3 pages a,b and c.

Page a has been completed so i then move onto page b, so i put all the page a variables into a session array then on page b i continue to fill things in but how do i then add the variables from page b to that session array as when i get to page c i want to display all of page a variables and all of page b for the user to check what he inputed.

Any Ideas

Thanks
k0r54

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJan 12.2005 — Page B:
[code=php]
$_SESSION = array_merge($_SESSION, $_POST);
[/code]

Page C:
[code=php]
$_SESSION = array_merge($_SESSION, $_POST);
[/code]

Really. ? (It's merging all the key/value pairs from the array_merge arguments into one array, which we're then (over)writing to the $_SESSION array in this case.)
Copy linkTweet thisAlerts:
@k0r54authorJan 12.2005 — So all i need to do is just keep adding them and it wont over write them.

1 more question though, how do i then view the individual field. For display perposes how could i view field First Name from page a on page c.

Thanks

Adam
Copy linkTweet thisAlerts:
@NogDogJan 12.2005 — [i]Originally posted by k0r54 [/i]

[B]So all i need to do is just keep adding them and it wont over write them.



1 more question though, how do i then view the individual field. For display perposes how could i view field First Name from page a on page c.



Thanks

Adam [/B]
[/QUOTE]

Assume Page A has form field defined:
[code=php]
<input name="first_name" type=text>
[/code]

In Page B, it would be available as [FONT=courier new][B]$_POST['first_name'][/B][/FONT]. When you do the [FONT=courier new][B]$_SESSION = array_merge($_SESSION, $_POST);[/B][/FONT] the value is now [i]also[/i] available [FONT=courier new][B]as $_SESSION['first_name'][/B][/FONT] in Page B and any subsequent pages using that session.

Do note, however, that if at any point you re-use a form field name (such as "first_name" in this case) at some point in the page sequence, it [i]will[/i] overwrite the $_SESSION variable with the same key.
×

Success!

Help @k0r54 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...