JMair Posted March 24, 2009 Share Posted March 24, 2009 How do pass a Var from 1.php to 2.php? note, 1.php and 2.php are in two diff folders. Can anybody give a quick example, or point me in the correct direction? Very glad I've found this site. I took a PHP class about a year ago and now wishing I retained a little more :-\ Quote Link to comment https://forums.phpfreaks.com/topic/150951-solved-pass-var-simple-question/ Share on other sites More sharing options...
Maq Posted March 24, 2009 Share Posted March 24, 2009 page1.php Click Here page2.php echo $_GET['var']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/150951-solved-pass-var-simple-question/#findComment-793045 Share on other sites More sharing options...
WolfRage Posted March 24, 2009 Share Posted March 24, 2009 LOL I mean yes like Maq stated. Use $_GET, $_POST, $_COOKIE, $_SESSION, Write it to a database, or write it to a file. Quote Link to comment https://forums.phpfreaks.com/topic/150951-solved-pass-var-simple-question/#findComment-793046 Share on other sites More sharing options...
JMair Posted March 24, 2009 Author Share Posted March 24, 2009 I didnt clearify my problem. Here's is an example of my problem. It's getting php return to be sent over to page2.php along with the form action. The _Get or _POST works fine with the form, but not the php... 1.php <form action= "subdirectory/2.php" method="post"> <?php $YourGayUserName = 'Burt'; echo $YourGayUserName; ?> </p> <p>Select User: <select name="guser"> <option value="Select User">UnSelected</option> <option value="User1">Gay User One</option> <option value="User2">Gay User Two</option> <option value="User3">Gay Three</option> </select> <input type="submit" /> </p> </form> 2.php <?php echo $_GET['$YourGayUserName'] ."and " .$_POST['guser'];; ?> Quote Link to comment https://forums.phpfreaks.com/topic/150951-solved-pass-var-simple-question/#findComment-793112 Share on other sites More sharing options...
lonewolf217 Posted March 24, 2009 Share Posted March 24, 2009 your $_GET statement wont work. $_GET does not pull random variables from a previous page, it only pulls variables from the URL of the current page $_POST['guser'] should work just fine though Quote Link to comment https://forums.phpfreaks.com/topic/150951-solved-pass-var-simple-question/#findComment-793114 Share on other sites More sharing options...
JMair Posted March 25, 2009 Author Share Posted March 25, 2009 the result is and User1 I think this is because I have a php variable and Form variables and using the Form variable to 'submit' the form to the next page. The php variable is not properlly called. I hope I'm explaining myself correctly enough. Quote Link to comment https://forums.phpfreaks.com/topic/150951-solved-pass-var-simple-question/#findComment-793548 Share on other sites More sharing options...
Maq Posted March 25, 2009 Share Posted March 25, 2009 In this case you can just use a hidden field. page1.php </pre> <form action="subdirectory/2.php" method="POST"> $YourGayUserName = 'Burt'; echo $YourGayUserName; ?> Select User: UnSelected Gay User One Gay User Two Gay Three < 2.php Use the POST method for both vars: (You had an extra ';' here) echo $_POST['$YourGayUserName'] ." and " .$_POST['guser']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/150951-solved-pass-var-simple-question/#findComment-793551 Share on other sites More sharing options...
JMair Posted March 25, 2009 Author Share Posted March 25, 2009 page2.php <?php echo $_POST['YourGayUserName'] ." and " .$_POST['guser']; ?> YOU rock. Thank very much! Quote Link to comment https://forums.phpfreaks.com/topic/150951-solved-pass-var-simple-question/#findComment-793571 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.