473,657 Members | 2,458 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

carrying over variables from a form to multiple pages...

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.ph p" method="post">
<select name="color"><o ption value="blue">bl ue</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..th anks guys!

Jul 5 '07 #1
4 14097
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.ph p" method="post">
<select name="color"><o ption value="blue">bl ue</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..th anks 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.
js*******@attgl obal.net
=============== ===
Jul 5 '07 #2
On Jul 4, 9:27 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
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.ph p" method="post">
<select name="color"><o ption value="blue">bl ue</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..th anks 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...@attgl obal.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.

Jul 5 '07 #3
Message-ID: <11************ *********@d30g2 000prg.googlegr oups.comfrom
Kurrent contained the following:
>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.
Why rename?

foreach($_POST as $key=>$value){
//insert sanity check here
$_SESSION[$key]=$value;
}
But I'd probably do
foreach($_POST as $key=>$value){
//insert sanity check here
$_SESSION['data'][$key]=$value;
}

It's then a lot easier to get rid of the POSTed variables if you need to
ie unset($_SESSION['data'])

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 5 '07 #4
Kurrent wrote:
On Jul 4, 9:27 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
>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.ph p" method="post">
<select name="color"><o ption value="blue">bl ue</option><option
value="red">r ed</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..th anks 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...@attg lobal.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.
js*******@attgl obal.net
=============== ===
Jul 5 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
6266
by: Ralph Freshour | last post by:
I was reading about PHP variable scoping - it doesn't seem to support carrying any variables from one web page to another - how is this usually done? I have a lot of php variables created on my home page that I need to make use of on other web pages - how can I do that? Thanks...
2
2679
by: Martien van Wanrooij | last post by:
I am working on a site that will have several pages and where the user will find some investment advices. I must say that the concept of sessions/session variables is relatively new for me. What I noticed is the following: when I write "form method is ""post" action = page2.php", and in page2.php I write "session_register("someVariable") the value of the variable is registered but if I visit some further pages and go back to page1, I...
4
3329
by: Mike MacSween | last post by:
It's a form, with (so far) 4 tab pages on it, each of which holds 2/3/4 subforms. (I like tabbed forms by the way - do we all?) Basically the subforms are different ways of looking at the data. It's the orchestral management thing still. So tab 1 looks at each musician, the events they're booked onto, which jobs they're doing etc.
3
9409
by: Jessica Loriena | last post by:
I'm trying to write a simple "register form / validate and store in database / show welcome screen" application with ASP.Net. With conventional ASP, I used Session variables and it went something like this: ***** form.asp - <form action="ValidateAndStore.asp" method="post">
1
2076
by: Ani | last post by:
Hi, I need to carry the user input across pages and then at the end insert all the values into the DB. How do I best accomplish this task in ASP.Net. I am a novice , please give me some simple suggestions. Thanks.
1
1285
by: jamezw | last post by:
I have a web app that uses StateServer to track session. It is cookieless (e.g. session ID in the URL.) We have run into a problem that is like such: we have a page that has multiple frames on it. All the frames point to relative pages except one which points to a specific IP, but it is an IP that runs the same web application. The frame src looks something like this: src="http://{theip}/(sessionid)/Page.aspx". In essence, this should be...
14
2185
by: Coleen | last post by:
Hi All :-) We have an APSX application using VB.net as the code behind, which uses one or two session variables per page. These Session variables are passed to the final page and calculations and summaries are done there. In order for all of the values to appear on the last page, the user has to view each page that has a session variable to be passed to the last page. The only way I can think of to bypass the necessity of the user...
1
5060
devonknows
by: devonknows | last post by:
Hi, im having trouble carrying variables across a form, ive looked on here and other sites but cant find anything that helps me, or i might not be searching for the right terms, so i though i would post to see if anyone can help me. what i need is to carry certain aspects of data from splash form to my main form which im currently developing. this is the code im usign for the frmSplash Option Explicit Private Declare Function...
4
2920
cassbiz
by: cassbiz | last post by:
Could use some help here. This script is carrying over an image just fine but the text isn't coming over. can you see why it is not working???? from the form I want to carry over two lines of text and I can't find the error on why it isn't working. Any help is greatly appreciated. Here is the form
0
8325
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8844
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8742
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8518
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8621
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7354
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5643
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.