ksduded Posted September 11, 2008 Share Posted September 11, 2008 I want to carry a variable through three php pages. the variable is the first_name of the visitor which is entered through a form in an textfield. the form calls action to another php, where I am able to extract the variable by the use of the $_POST['first_name'] But that second php calls another php file called upload.php, where I want to use that variable again. But till the third php file I have lost it. I don't want to get in the complicated world of sessions. I heard that i can still carry it through separate pages through the use of a form.... how can i achieve that without showing anything on screen. Link to comment https://forums.phpfreaks.com/topic/123824-carrying-variables-over-multiple-pages/ Share on other sites More sharing options...
KevinM1 Posted September 11, 2008 Share Posted September 11, 2008 I want to carry a variable through three php pages. the variable is the first_name of the visitor which is entered through a form in an textfield. the form calls action to another php, where I am able to extract the variable by the use of the $_POST['first_name'] But that second php calls another php file called upload.php, where I want to use that variable again. But till the third php file I have lost it. I don't want to get in the complicated world of sessions. I heard that i can still carry it through separate pages through the use of a form.... how can i achieve that without showing anything on screen. Simply use a form with hidden inputs: Page 1 - <form action="page2.php" method="post"> <input type="text" name="user" /> . . . </form> Page 2 - <?php $user = $_POST['user']; . . . ?> <form action="page3.php" method="post"> <input type="hidden" name="user" value="<?php echo $user; ?>" /> . . . </form> Page 3 - <?php $user = $_POST['user']; ?> Link to comment https://forums.phpfreaks.com/topic/123824-carrying-variables-over-multiple-pages/#findComment-639323 Share on other sites More sharing options...
ksduded Posted September 12, 2008 Author Share Posted September 12, 2008 Now that I see the code, it seem that I will have trouble implementing that technique, cause the third file is called through a flash/javascript file and its integrated in a way where I won't be able to use forms. Sorry for that. I guess my only option is to use sessions. For testing purposes I have created three files which carry a variable over, but it does not seem to work at my end. page1.php <form id="user" method="post" action='page2.php'> <fieldset > <legend>User Information</legend> <table width="650"> <tr><td width="100" align="right"> First Name</td> <td align="left"> <input name="first_name" type="text" class="formtextfield"/></td></tr> <input name="I Accept" type="submit" /></td></tr></table> </fieldset> </form> page2.php <?php session_start(); $first_name = $_SESSION['first_name']; ?> <form action="page3.php" method="post"> <input name="Submit" type="submit"> </form> page3.php <?php session_start(); $first_name = $_SESSION['first_name']; echo "This is my".$first_name; ?> Help will be appreciated. Link to comment https://forums.phpfreaks.com/topic/123824-carrying-variables-over-multiple-pages/#findComment-639825 Share on other sites More sharing options...
kenrbnsn Posted September 12, 2008 Share Posted September 12, 2008 You have to store the value before you use it. in page2.php <?php session_start(); $_SESSION['first_name'] = $_POST['firstname']; ?> Ken Link to comment https://forums.phpfreaks.com/topic/123824-carrying-variables-over-multiple-pages/#findComment-639829 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.