kannu Posted November 23, 2008 Share Posted November 23, 2008 Hello, I passed the variable from 1st to 2nd page successfully with the following code: 1st page code:- <form action="a2008.php" method="POST"> <input type="hidden" id="answer" name="answer" value="<?php echo $_SESSION["answer"] ?>"/> <input type="image" name="submit" src=button.jpg" /> </form> 2nd page code to retrieve the variable:- <? $answer=$_POST['answer']; if ($answer !="layaway") { $answer = "complete"; } echo $answer; ?> This retrieves the value successfully. Now, I need to pass it to the third page and I use the following code as used before, but it does not work:- <form action="conf.php" method="POST"> <input type="hidden" name="answer" value="<?php echo $_SESSION["answer"] ?>"/> <input type="image" name="submit" src="button.jpg" > </form> When I try to retrieve it on the 3rd page, I do not get any value. Can you please help me out at this. I have spent over 5 hours to work this out, and I dont know how, I am new to the php coding. thanks Link to comment https://forums.phpfreaks.com/topic/133896-need-help-passing-variable-from-2nd-to-3rd-page/ Share on other sites More sharing options...
webmaster1 Posted November 23, 2008 Share Posted November 23, 2008 Use the code tags if you want the brainchilds to review your query. Link to comment https://forums.phpfreaks.com/topic/133896-need-help-passing-variable-from-2nd-to-3rd-page/#findComment-696993 Share on other sites More sharing options...
flyhoney Posted November 23, 2008 Share Posted November 23, 2008 You must place session_start() at the beginning of your script before you can use $_SESSION to pass data from page to page. Link to comment https://forums.phpfreaks.com/topic/133896-need-help-passing-variable-from-2nd-to-3rd-page/#findComment-697011 Share on other sites More sharing options...
kannu Posted November 23, 2008 Author Share Posted November 23, 2008 I am posting the same question again, using the code tags, so that it is easier to understand. I have the code session_start() at the beginning of my script already. My question is, if someone can help me:- Hello, I passed the variable from 1st to 2nd page successfully with the following code: 1st Page code <form action="a2008.php" method="POST"> <input type="hidden" id="answer" name="answer" value="<?php echo $_SESSION["answer"] ?>"/> <input type="image" name="submit" src=button.jpg" /> </form> 2nd page code to retrieve the variable:- <? $answer=$_POST['answer']; echo $answer; ?> This retrieves the value successfully. Now, I need to pass it to the third page and I use the following code as used before, but it does not work:- <form action="conf.php" method="POST"> <input type="hidden" name="answer" value="<?php echo $_SESSION["answer"] ?>"/> <input type="image" name="submit" src="button.jpg" > </form> When I try to retrieve it on the 3rd page, I do not get any value. Can you please help me out at this. I have spent over 5 hours to work this out, and I dont know how, I am new to the php coding. thanks Link to comment https://forums.phpfreaks.com/topic/133896-need-help-passing-variable-from-2nd-to-3rd-page/#findComment-697267 Share on other sites More sharing options...
waynew Posted November 23, 2008 Share Posted November 23, 2008 Safest = using session variables. Quick fix = hidden form fields. Link to comment https://forums.phpfreaks.com/topic/133896-need-help-passing-variable-from-2nd-to-3rd-page/#findComment-697271 Share on other sites More sharing options...
laPistola Posted November 23, 2008 Share Posted November 23, 2008 on second page that links to page 3 add this YOURLINKYOUR.php?answer=$answer and the on page 3 <form action="conf.php" method="POST"> <input type="hidden" name="answer" value="<?php echo $_GET["answer"] ?>"/> <input type="image" name="submit" src="button.jpg" > </form> Link to comment https://forums.phpfreaks.com/topic/133896-need-help-passing-variable-from-2nd-to-3rd-page/#findComment-697272 Share on other sites More sharing options...
xtopolis Posted November 23, 2008 Share Posted November 23, 2008 $_SESSION['answer'] should still contain the value from the beginning, in your snippets I don't see it being updated/deleted anywhere. As flyhoney suggested, are you sure session_start() is at the top of all 3 forms? Sessions and form POST data have nothing to do with each other. You can retrieve a session variable regardless of a form as long as the current page is part of the session (session_start()). Passing post variables in a form chain would be like: form1 <form action="form2.php" method="post"> <input type="text" name="passMe1" /> //<- user inputs "5" form2 <form action="form3.php" method="post"> <input type="text" name="passMe2" value="<?php echo $_POST['passMe1']; ?>" />//<-- shows 5 form3 <form action="" method="post"> <input type="type" name="final" value="<?php echo $_POST['passMe2']; ?>" /> //<-- shows 5 ---------------------------- sessions page1.php <?php session_start(); $_SESSION['passMe'] = 'Hello World'; ?> anyotherpage.php <?php session_start(); echo $_SESSION['passMe']; //outputs Hello World ?> Link to comment https://forums.phpfreaks.com/topic/133896-need-help-passing-variable-from-2nd-to-3rd-page/#findComment-697289 Share on other sites More sharing options...
flyhoney Posted November 24, 2008 Share Posted November 24, 2008 You need to modify your second page code: <? session_start(); $answer=$_POST['answer']; $_SESSION['answer'] = $answer; ?> Link to comment https://forums.phpfreaks.com/topic/133896-need-help-passing-variable-from-2nd-to-3rd-page/#findComment-697767 Share on other sites More sharing options...
kannu Posted November 27, 2008 Author Share Posted November 27, 2008 hey, thanks guys to all of you for all the help and time to sort my problem. I am finally able to work it out, and a special thanks to member "xtopolis" whose solution was the one that worked thanks again Link to comment https://forums.phpfreaks.com/topic/133896-need-help-passing-variable-from-2nd-to-3rd-page/#findComment-700364 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.