|
Posted by Jerry Stuckle on 07/05/07 03:27
Kurrent wrote:
> I have some data from text fields that are being passed over through a
> form that I am displaying with the $_POST superglobal. Once i have
> echo'd out this data onto the next page, i'd like to continue to use
> it on the next page. I haven't figured out how to do this properly
> just yet, but I'm guessing it has something to do with sessions. I
> have MANY variables being passed (over 100) and I'm hoping i don't
> have to register each one of these manually with $_SESSION[].
>
> example.
>
> //first page (index.html)
>
> <form action="form.php" method="post">
> <select name="color"><option value="blue">blue</option><option
> value="red">red</option>
> <input name="submit" type="submit">
>
> //new page (form.php)
> <?php
> echo "Bill's favorite color is {$_POST['color']}";
> ?>
> ////
>
> Now say I want to use this $_POST['color'] value on another page that
> the form.php takes you to next.....how do i continue to use this value
> across multiple pages?
>
> I'm assuming this is a trivial question, but i can't seem to figure it
> out! Any help is much appreciated..thanks guys!
>
Two ways - make them hidden fields on each page (only works if you're
using forms), or store each one in the $_SESSION superglobal, i.e.
<?php
session_start();
$_SESSION['color'] = $_POST['color'];
?>
And when you want to use it:
<?php
session_start();
$color = $_SESSION['color'];
?>
Of course you will want to validate the entries to ensure they exist,
contain valid values, etc. (never assume $_POST data is accurate!).
But hopefully you get the idea.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Navigation:
[Reply to this message]
|