12 Replies - 87719 Views - Last Post: 07 September 2005 - 04:18 AM Rate Topic: -----

#1 scofansnags  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 11
  • Joined: 29-August 05

Passing variables from one page to another

Posted 29 August 2005 - 04:34 AM

Can someone please help me? I am trying to pass the variables in a form from one page to another. Could someone take the time to walk me through this? I do not know anything about PHP. :huh:

Thanks in advance,

Scofansnags
Is This A Good Question/Topic? 2

Replies To: Passing variables from one page to another

#2 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Passing variables from one page to another

Posted 29 August 2005 - 06:00 AM

Passing the variables from a form to another page depends on the method of your form...for the purposes of this explanation, I will assume your form has an method of POST.

Page1
<form name="form1" action="page2.php" method="post">
<input type="text" name="var1" value="">
<input type="submit" name="submit" value="submit">
</form>



Page2
$variable_from_page1 = $_POST['var1'];



Here is an explanation straight from the PHP manual.
Was This Post Helpful? 1

#3 scofansnags  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 11
  • Joined: 29-August 05

Re: Passing variables from one page to another

Posted 29 August 2005 - 09:29 AM

Thanks for the codes and the referrence:

From my page:
<form method="POST" name="myform" action="http://us.1.p2.webhosting.yahoo.com/forms?login=scofansnags" >

How do I reconcile action="page2.php" with what I already have above? Is it just added?

and where does this go on my page? ? in the form tag?
Page2 code
$variable_from_page1 = $_POST['var1'];


I have 4 pages to my form, so is a prgression of the varibles just added to ea page? Like,
$variable_from_page1 = $_POST['var1'];
$variable_from_page2 = $_POST['var2']; ...etc.
Was This Post Helpful? 0
  • +
  • -

#4 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Passing variables from one page to another

Posted 29 August 2005 - 10:22 AM

You will have to replace page2.php with whatever action (or URL) you are sending the information to.

As for the code location, I am going to assume that you are referring to the php code

$variable_from_page1 = $_POST['var1'];


Please correct me if I am wrong...that code will go into whatever section on the page your are having php code perform some processing actions. It is possible that you do not so any processing on page 2, if you are simply passing the information to the next page.

For passing the information, I'll make the assumption that there is a form on each page...if you are merely passing the information, you can do it like this. Imagine this is the second page (page2.php)
<form name="form2" action="page3.php" method="post">
<input type="hidden" name="var1" value="<?=$_POST['var1'];?>"/>
<input type="submit" name="submit" value="submit"/>
</form>


That code will place the value of var1 from the first page into a variable called var1 on the second page, and can be accessed on the third page in either of the manners described earlier.
Was This Post Helpful? 1
  • +
  • -

#5 scofansnags  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 11
  • Joined: 29-August 05

Re: Passing variables from one page to another

Posted 29 August 2005 - 12:40 PM

Yes, just want to pass the information on
from page-to-page until the last page. Here the visitor hits the submit button and all of the informaiton is submitted at one time.

Does this look like I'm getting close? What's wrong with what I've done?
Please go slowly :(

Form 1
<form method=post onsubmit="return formCheck(this);" name="form1" action="http://us.1.p2.webhosting.yahoo.com/forms?login=scofansnags" $variable_from_page1 = $_POST['var1'];>



Form 2
<form method=post onsubmit="return formCheck(this);" name="form2" action="http://us.1.p2.webhosting.yahoo.com/forms?login=scofansnags">
<input type="hidden" name="var1" value="<?=$_POST['var1'];?>"/>



and for submission on page2:
<INPUT class="button" type=submit value="="submit"/>

thanx,
scofansnags
Was This Post Helpful? 0
  • +
  • -

#6 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Passing variables from one page to another

Posted 29 August 2005 - 12:45 PM

Form 1
<form name="form1" action="page2.php" method="post">
<input type="text" name="var1" value="">
<input type="submit" name="submit" value="submit">
</form>



Form2 on a separate web page
<form name="form2" action="page3.php" method="post">
<input type="hidden" name="var1" value="<?=$_POST['var1'];?>"/>
<input type="submit" name="submit" value="submit"/>
</form>



It should be noted that you are supplying the same URL as the action for both forms...did you not specify that you will be sending the information through different pages?
Was This Post Helpful? 0
  • +
  • -

#7 scofansnags  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 11
  • Joined: 29-August 05

Re: Passing variables from one page to another

Posted 29 August 2005 - 02:23 PM

Thanks Amadeus for your patience with this real newbie!

In layman's terms, I have an examination that will be taken online. The exam consists of 200 questions which would be an extremely long page. I plan on splitting the pages into 4 pages with 25 questions per page. Each page will carry over the answers from the first page until the visitor reaches the last page where they will hit the submit button and send all of the answers to the four pages at one time. So, you questioned the URL. Wouldn't it be the same URL?

Scofansnags
Was This Post Helpful? 0
  • +
  • -

#8 scofansnags  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 11
  • Joined: 29-August 05

Re: Passing variables from one page to another

Posted 29 August 2005 - 02:25 PM

Oops, I mean 50 questions per page, of course.

Scofansnags
Was This Post Helpful? 0
  • +
  • -

#9 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Passing variables from one page to another

Posted 29 August 2005 - 03:08 PM

Well, that's up to you...you can either have one page, or 4 pages to accomplish this. Using 4 separate pages and passing the variables along may be easier from a design point of view, while using one page is more efficient space wise. Essentially you can either use the method we've been discussing (4 pages), or set up one page to submit to itself and display a different set of questions each time until completed. Even using this method, you are likely to have a slightly different URL, as you will want to set some sort of flag to determine which set of questions to display (perhaps through the querystring).

It really depends what you feel more comfortable with.

And no worries about the help, my friend...that's what we're here for! :)
Was This Post Helpful? 0
  • +
  • -

#10 scofansnags  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 11
  • Joined: 29-August 05

Re: Passing variables from one page to another

Posted 29 August 2005 - 06:55 PM

Yes, I would prefer 4 pages. I have no trouble setting up a bisic one page form...


If I alter this Geocities address (and I wouldn't know where to start), since this is what Geocities says I must use to get my forms delivered to me, wouldn't this interfer with the function of delivering the form? If not, how would I alter it?

<form method="POST" name="myform" action="http://us.1.p2.webhosting.yahoo.com/forms?login=scofansnags" >
Was This Post Helpful? 0
  • +
  • -

#11 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Passing variables from one page to another

Posted 30 August 2005 - 02:26 AM

To be honest, I'd have to know a little bit more about your hosting setup...for instance, can you tell me if you only have access to that one page? Or can you upload several files to the server? Have you verified that your hosting account is set up to interpret (read run) scripting languages such as PHP?
Was This Post Helpful? 0
  • +
  • -

#12 scofansnags  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 11
  • Joined: 29-August 05

Re: Passing variables from one page to another

Posted 30 August 2005 - 07:55 AM

Yes, Amadeus, to both questions.
Was This Post Helpful? 0
  • +
  • -

#13 cybrid  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 35
  • Joined: 07-September 05

Re: Passing variables from one page to another

Posted 07 September 2005 - 04:18 AM

I'm not very good at XML, but another option you may have, is to send all the data to a XML file, and store the information in it through all the 4 pages, and when you are done, parse it to add the info to your database. Don't ask me for code for I still have to learn a lot of XML.

Another option I see, is declaring a global Array, store all the info there and then after passing the 4 pages, send the data to your database.

Those are just a pair of ideas. Hope I can be of any help :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1