dasein Posted October 6, 2008 Share Posted October 6, 2008 Hi, I'm trying to sort out what's deprecated in passing a variable from .php page to .php page. I'm getting more and more confused trying to sort it all out. I've got three files (test.html, test1.php, test2.php). I've been toying with different things but can only get a variable from the html page to show up in test1.php. It won't pass though to test2.php and I've tried about every variant I can find from tutorials and such. THE HTML FILE: <html> <head><title>TEST</title> </head> <body bgcolor="#ffffff"> <center><p> <form name="test" action="test1.php" method="post"> Name: <input type=text name=username><p> </center> <input type=submit value="SUBMIT"> <input type=reset value="RESET ALL"> </form> </body> </html> THE test1.php FILE: <?php session_start(); $username = isSet($_POST['username']) ? $_POST['username'] : ''; $_SESSION['username'] = $username; //echo "USERNAME: $username<p>"; session_register('username'); header("location: test2.php"); ?> THE test2.php FILE: <?php session_start(); echo "USERNAME in TEST2:$username<p>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/127189-reg-vars/ Share on other sites More sharing options...
ngreenwood6 Posted October 6, 2008 Share Posted October 6, 2008 Your coding is all messed up. Please if you post as well use the code tag if you post code. Here is an example index.html <html> <body> <form method="post" action="index.php"> Name: <input type="text" name="username"> </form> </body> </html> index.php <?php //set the variable $username from the form $username = $_POST['username']; //write the variable to the page echo $username; ?> This is a pretty basic example. Please let me know if this helps. Quote Link to comment https://forums.phpfreaks.com/topic/127189-reg-vars/#findComment-657921 Share on other sites More sharing options...
genericnumber1 Posted October 6, 2008 Share Posted October 6, 2008 don't use session_register(). You can remove that line as you already set the session variable with $_SESSION['username'] = $username; You call it by the same variable: $_SESSION['username']; so make it.. <?php session_start(); echo "USERNAME in TEST2:$_SESSION['username']"; ?> If you enable E_NOTICE it warns you if you use a depreciated function. Quote Link to comment https://forums.phpfreaks.com/topic/127189-reg-vars/#findComment-657922 Share on other sites More sharing options...
dasein Posted October 6, 2008 Author Share Posted October 6, 2008 Hey thanks...that does work. I haven't done much in a few years and am amazed at the modifications they've introduced. I guess I should go back to square one and learn from scratch again how things are properly coded...thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/127189-reg-vars/#findComment-657925 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.