Reply to Re: carrying over variables from a form to multiple pages...

Your name:

Reply:


Posted by Jerry Stuckle on 07/05/07 14:52

Kurrent wrote:
> On Jul 4, 9:27 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
>> 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.
>> jstuck...@attglobal.net
>> ==================
>
> ack, this is close to what i originally did...on my second page i made
> all the default values in a form the carried over values, but i have
> so many variables i was hoping i don't have to register them one-by-
> one. Looks like i'm gonna have to rename my values and make some sort
> of loop to register them all.
>

Geoff has some good ideas on how to handle it. But you don't have to
register variables in the session. Just set the key/value pair in the
$_SESSION variable, as above.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация