sseeley Posted December 23, 2008 Share Posted December 23, 2008 Hi I am trying to use the following code but the text in the field will not carry accross to the second page, can anyone help? sessionTest1.php <?php session_start(); ?> <html? <head> <title>Testing Sessions</title> </head> <body> <?php $_SESSION['session_var'] = "Testing"; echo "This is a test of the session feature. <form action='sessionTest2.php' method='POST'> <input type='text' name='test'> <input type='submit' value='go'> </form>"; $_SESSION['session_var1'] = $_POST['test']; ?> </body> </html> sessionTest2.php <?php session_start(); ?> <html? <head> <title>Testing Sessions 2</title> </head> <body> <?php if ( @$_SESSION['session_var'] == "Testing" ) { echo $_SESSION['session_var']; echo $_SESSION['session_var1']; } ?> </body> </html> Many thanks in advance Link to comment https://forums.phpfreaks.com/topic/138250-solved-sessions/ Share on other sites More sharing options...
PFMaBiSmAd Posted December 23, 2008 Share Posted December 23, 2008 Add the following two lines of code immediately after your first opening <?php tag on both pages - ini_set ("display_errors", "1"); error_reporting(E_ALL); Link to comment https://forums.phpfreaks.com/topic/138250-solved-sessions/#findComment-722794 Share on other sites More sharing options...
ngreenwood6 Posted December 23, 2008 Share Posted December 23, 2008 you should use code tags when posting on this site but your setting a session value as a post value in sessionTest1.php when the page hasn't been posted yet. you need to set the session value on sessionTest2.php like this: sessionTest1.php <html> <head> <title>Testing Sessions</title> </head> <body> This is a test of the session feature. <form action='sessionTest2.php' method='post'> <input type='text' name='test'> <input type='submit' name='submit' value='go'> </form> </body> </html> sessionTest2.php <?php session_start(); ?> <html> <head> <title>Testing Sessions 2</title> </head> <body> <?php //get the variables $test = $_POST['test']; $submit = $_POST['submit']; if ($submit) //if the form is submitted { $_SESSION['session_var'] = $test; } echo $_SESSION['session_var']; ?> </body> </html> that should work for you. I am assuming you are just trying to figure out how to use sessions? Link to comment https://forums.phpfreaks.com/topic/138250-solved-sessions/#findComment-722798 Share on other sites More sharing options...
sseeley Posted December 23, 2008 Author Share Posted December 23, 2008 I recieve the following error... Notice: Undefined index: test in /home/mypcguy2/public_html/atcsquadron.co.uk/middlesexwing/sports/sessionTest1.php on line 18 Line 18 is the following... $_SESSION['session_var1'] = $_POST['test']; Thanks Link to comment https://forums.phpfreaks.com/topic/138250-solved-sessions/#findComment-722799 Share on other sites More sharing options...
sseeley Posted December 23, 2008 Author Share Posted December 23, 2008 Thanks for your help, yes I am trying to learn sessions, just want to pass information from a text field from one page to another...but I get the following error... Parse error: syntax error, unexpected T_STRING, expecting '(' in /home/mypcguy2/public_html/atcsquadron.co.uk/middlesexwing/sports/sessionTest2.php on line 16 Link to comment https://forums.phpfreaks.com/topic/138250-solved-sessions/#findComment-722804 Share on other sites More sharing options...
ngreenwood6 Posted December 23, 2008 Share Posted December 23, 2008 can you post your two pages again and let me know which line is 16 edit: please use the code tags (it is the # symbol). Link to comment https://forums.phpfreaks.com/topic/138250-solved-sessions/#findComment-722805 Share on other sites More sharing options...
sseeley Posted December 23, 2008 Author Share Posted December 23, 2008 Thanks for your help, I have just played about with the code and now have it working...I can progress from here...again many thanks for this help now...and I am sure possibly in the future. Regards Link to comment https://forums.phpfreaks.com/topic/138250-solved-sessions/#findComment-722806 Share on other sites More sharing options...
ngreenwood6 Posted December 23, 2008 Share Posted December 23, 2008 no problem and remember to mark this thread as topic solved. Link to comment https://forums.phpfreaks.com/topic/138250-solved-sessions/#findComment-722808 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.