williamZanelli Posted August 28, 2008 Share Posted August 28, 2008 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 More sharing options...
pocobueno1388 Posted August 28, 2008 Share Posted August 28, 2008 Store all the post data in a session...that way you have it for as long as you need. Link to comment https://forums.phpfreaks.com/topic/121725-solved-passing-values-from-page-to-page/#findComment-627939 Share on other sites More sharing options...
williamZanelli Posted August 28, 2008 Author Share Posted August 28, 2008 Can you post some example code please Thanks Link to comment https://forums.phpfreaks.com/topic/121725-solved-passing-values-from-page-to-page/#findComment-628000 Share on other sites More sharing options...
BlueSkyIS Posted August 28, 2008 Share Posted August 28, 2008 first page: <?php session_start(); $_SESSION['yoMama'] = "Hello World"; exit; ?> second page: <?php session_start(); echo $_SESSION['yoMama']; ?> output: Hello World Link to comment https://forums.phpfreaks.com/topic/121725-solved-passing-values-from-page-to-page/#findComment-628010 Share on other sites More sharing options...
rhodesa Posted August 28, 2008 Share Posted August 28, 2008 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 ?> Link to comment https://forums.phpfreaks.com/topic/121725-solved-passing-values-from-page-to-page/#findComment-628014 Share on other sites More sharing options...
williamZanelli Posted August 28, 2008 Author Share Posted August 28, 2008 Thanks for the reply Rhodesa, I'll give it a go. Link to comment https://forums.phpfreaks.com/topic/121725-solved-passing-values-from-page-to-page/#findComment-628025 Share on other sites More sharing options...
williamZanelli Posted August 29, 2008 Author Share Posted August 29, 2008 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 Link to comment https://forums.phpfreaks.com/topic/121725-solved-passing-values-from-page-to-page/#findComment-628701 Share on other sites More sharing options...
rhodesa Posted August 29, 2008 Share Posted August 29, 2008 Not sure why it can't find the page. Double check your filenames and their locations again. As for the second page, the session_start() needs to be the VERY FIRST thing on the page....before any other PHP or HTML code Link to comment https://forums.phpfreaks.com/topic/121725-solved-passing-values-from-page-to-page/#findComment-628707 Share on other sites More sharing options...
williamZanelli Posted August 29, 2008 Author Share Posted August 29, 2008 Thanks for the reply Rhodesa. I typed the wrong name of the file, whcih had to deal with the PHP form : Thnaks for the help. Have a great day. Link to comment https://forums.phpfreaks.com/topic/121725-solved-passing-values-from-page-to-page/#findComment-628770 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.