Jump to content

[SOLVED] Passing values from page to page


williamZanelli

Recommended Posts

Hi guys,

 

I have a small problem, just wondering if you could help me.

 

I have a PHP form, a quiz, as below

 

<form action="compute.php" method="post">
<br/><li>Question 1 is...</li>
<p><input type="radio" name="Q1" value = "1"  />    Answer a - one possible answer <br /> 
    <input type="radio" name="Q1" value = "2"  />     Answer b - one possible answer <br />
   <input type="radio" name="Q1" value = "3"  />     Answer c - one possible answer<br />
</p>
  <br/><li>Question 2 is...</li>
<p><input type="radio" name="Q2" value = "1"  />    Answer a - one possible answer <br /> 
    <input type="radio" name="Q2" value = "2"  />     Answer b - one possible answer <br />
   <input type="radio" name="Q2" value = "3"  />     Answer c - one possible answer<br />
</p>
<input type="submit" value="Submit.."/>		  
  </form>

 

Currently when the above is submitted it goes to compute.php which computes some values [depending on $post values] and outputs something. This works!

 

What I want to do is forward to some other page in between, such as middlePage.php, display something, from here a user has the choice of click and go to compute.php - How do I keep the $post data alive??

 

As in,

 

User submits form --> middle page --> computer.php - how do I get access the $post data in computer.php.

 

Thanks in advance for your thoughts. Some code examples would be useful.

 

Will

 

Link to comment
https://forums.phpfreaks.com/topic/121725-solved-passing-values-from-page-to-page/
Share on other sites

first page: is your form, no change there...

 

second page:

<?php
  session_start();
  $_SESSION['post_data'] = $_POST;
?>
Here is a message. <a href="page3.php">Click here to calculate</a>

 

third page:

<?php
  session_start();
  $post = $_SESSION['post_data'];
  //Calculate data based on values in $post
?>

Hi there,

 

Ok well I got round to testing the code, I'm getting error, could anyone tell me whats wrong with the second page?

 

The first page is as below [though the form is submitted to the compute1.php],

 

The 2nd page, compute1.php is as below

 


<body>

<?php

session_start();
  $_SESSION['post_data'] = $_POST;

echo ("This is some middle page..");
?>

<br/>
<p><a href="http://someQuiz.com/Quiz/compute.php">Click</a> here to recieve your results. </p>


 

The final page, compute.php is

 

session_start();
  $post = $_SESSION['post_data'];

 

Once I click submit on the first page I get an error 404.

 

"POST /Quiz/compute1.php HTTP/1.1" 404 - "http://SomeQuiz.com/Quiz/Quiz.php" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; InfoPath.2)"

 

Any ideas..

 

Thanks in advance

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.