Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 17th, 2005, 10:58 AM
Quinonez
Guest
 
Posts: n/a
Default $_sessions

how do you save multiple variables in a multiple page form to $_SESSION
in order to retrieve them later...?

  #2  
Old July 17th, 2005, 10:58 AM
jOrdi3.tar.gz@gmail.com
Guest
 
Posts: n/a
Default Re: $_sessions

Quinonez,

I assume you are asking how to set and use sessions. In order to use
sessions you must put the following at the very top of every page.

<?php session_start(); ?>

Once you have done that you can use sessions on the page. Now to set a
session you do the following

$_SESSION['name']="John";

This will set the session named, "name" with the value of "John." Then
you could echo it back out like so.

echo $_SESSION['name'];

and it would print out the word, 'John.' I hope this is what you
wanted. :)

  #3  
Old July 17th, 2005, 10:58 AM
jOrdi3.tar.gz@gmail.com
Guest
 
Posts: n/a
Default Re: $_sessions

If you need further help check out this page on Sessions. ->
http://us2.php.net/manual-lookup.php...ssions&lang=en

  #4  
Old July 17th, 2005, 10:58 AM
jOrdi3.tar.gz@gmail.com
Guest
 
Posts: n/a
Default Re: $_sessions

Quinonez,

I assume you are asking how to set and use sessions. In order to use
sessions you must put the following at the very top of every page.

<?php session_start(); ?>

Once you have done that you can use sessions on the page. Now to set a
session you do the following

$_SESSION['name']="John";

This will set the session named, "name" with the value of "John." Then
you could echo it back out like so.

echo $_SESSION['name'];

and it would print out the word, 'John.' I hope this is what you
wanted. :)

  #5  
Old July 17th, 2005, 10:58 AM
Quinonez
Guest
 
Posts: n/a
Default Re: $_sessions

it does,
another question though is i have a form w. multiple variables its
actually a multiple page form and what i was wondering is if there is
away other than just setting up a $_SESSION['variablename'] for each
variable is there a way to have it save itself so that i can call at
the end of the form

  #6  
Old July 17th, 2005, 10:58 AM
Quinonez
Guest
 
Posts: n/a
Default Re: $_sessions

yea but i have a lot of variables in a multiple page form do i have to
set it up like that for every variable or can it be automated and then
called at the end?

  #7  
Old July 17th, 2005, 10:58 AM
jOrdi3.tar.gz@gmail.com
Guest
 
Posts: n/a
Default Re: $_sessions

I guess you could do something like the following. On your html page
with all of the forms you could make the name attribute to a number
starting from 0 and going up. Here is an example of what I mean.

--------------[ HTML File ] -----------------------------
<!----Messy HTML Code. Example only.--->
<html>
<head><title>Test Page</title></head>
<body>
<b>Enter your name: </b><input type="text" name="0">
<b>Enter your phone: </b><input type="text" name="1">
<form action="file.php" method="post">
<input type="submit" value="Submit"></form>
</body></html>

---------------------------------------------------------------------

---------------[File.php]--------------------------------------------

<?php

session_start();

for($m=0;$m<2;$m++)
{
$_SESSION['$m']=$_POST['$m'];
}

?>

----------------------------------------------------------

The above code should work. If it dosen't then it's because $m dosen't
need to be in the '. This code is only to give you an example of what I
mean. :)

  #8  
Old July 17th, 2005, 10:58 AM
Pedro Graca
Guest
 
Posts: n/a
Default Re: $_sessions

Quinonez wrote:[color=blue]
> yea but i have a lot of variables in a multiple page form do i have to
> set it up like that for every variable or can it be automated and then
> called at the end?[/color]


==== page1.php
$_SESSION['page1'] = $_POST;

==== page2.php
$_SESSION['page2'] = $_POST;
echo $_SESSION['page1']['name'];

--
Mail to my "From:" address is readable by all at http://www.dodgeit.com/
== ** ## !! ------------------------------------------------ !! ## ** ==
TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
may bypass my spam filter. If it does, I may reply from another address!
  #9  
Old July 17th, 2005, 10:58 AM
Quinonez
Guest
 
Posts: n/a
Default Re: $_sessions

"==== page2.php
$_SESSION['page2'] = $_POST;
echo $_SESSION['page1']['name'];"

what am i supposed to put in where it says ['name']? where do i get
that from?

thank for all your help.. i love the groups!

  #10  
Old July 17th, 2005, 10:58 AM
Pedro Graca
Guest
 
Posts: n/a
Default Re: $_sessions

Quinonez wrote:[color=blue]
> "==== page2.php
> $_SESSION['page2'] = $_POST;
> echo $_SESSION['page1']['name'];"
>
> what am i supposed to put in where it says ['name']? where do i get
> that from?[/color]

Try

==== page2.php
echo '<pre>'; print_r($_SESSION['page1']); echo '</pre>';

--
Mail to my "From:" address is readable by all at http://www.dodgeit.com/
== ** ## !! ------------------------------------------------ !! ## ** ==
TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
may bypass my spam filter. If it does, I may reply from another address!
  #11  
Old July 17th, 2005, 10:59 AM
Marc Cooper
Guest
 
Posts: n/a
Default Re: $_sessions

Pedro Graca said...[color=blue]
> Quinonez wrote:[color=green]
> > "==== page2.php
> > $_SESSION['page2'] = $_POST;
> > echo $_SESSION['page1']['name'];"
> >
> > what am i supposed to put in where it says ['name']? where do i get
> > that from?[/color]
>
> Try
>
> ==== page2.php
> echo '<pre>'; print_r($_SESSION['page1']); echo '</pre>';[/color]

Also, consider using an object.

--
Best,
Marc

www.auxbuss.com
'SX Unleashed' is on the way.
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles