ngreenwood6 Posted August 7, 2008 Share Posted August 7, 2008 I am in need of some help with sessions. I have 3 files: index.php (the form): <table border="1"> <form name="session" method="post" action="session.php"> <tr> <td>Username <td>: <td><input name="username" type="text"> </tr> <tr> <td>Email <td>: <td><input name="email" type="text"> </tr> <tr> <td> <td> <td><input name="submit" type="submit" value="submit"> </form> </table> sessions.php (registering the session variable): <?php session_start(); $myusername = $_POST['username']; $_SESSION['username'] = $myusername; $_SESSION['email'] = $_POST['email']; echo "Go to <a href='test.php'>Test</a>"; ?> test.php (showing the variable): <?php session_start(); echo $myusername; ?> Whenever I submit the form it goes to the sessions page. Then i go to the test page where it should display the username that was submitted but it isn't showing anything. I am trying to get it so that I can set variables (ex. $myusername) in the page so that it is easier to call at another time. If anyone can tell me why this isnt showing the username that would be great. Link to comment https://forums.phpfreaks.com/topic/118655-solved-sessions/ Share on other sites More sharing options...
lemmin Posted August 7, 2008 Share Posted August 7, 2008 Try echo $_SESSION['username']; instead of echo $myusername; Link to comment https://forums.phpfreaks.com/topic/118655-solved-sessions/#findComment-610883 Share on other sites More sharing options...
ngreenwood6 Posted August 7, 2008 Author Share Posted August 7, 2008 It will display it if I do it like that, but I am trying to get it so that it will display it when I do it with the $myusername. Anyone know how to accomplish this? Link to comment https://forums.phpfreaks.com/topic/118655-solved-sessions/#findComment-610886 Share on other sites More sharing options...
DarkWater Posted August 7, 2008 Share Posted August 7, 2008 $myusername = $_SESSION['username']; echo $myusername; ...? Link to comment https://forums.phpfreaks.com/topic/118655-solved-sessions/#findComment-610889 Share on other sites More sharing options...
ngreenwood6 Posted August 7, 2008 Author Share Posted August 7, 2008 Cool i've got it now. Link to comment https://forums.phpfreaks.com/topic/118655-solved-sessions/#findComment-610897 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.