shawnm Posted September 6, 2008 Share Posted September 6, 2008 I'm still battling with php sessions. Below is what was kindly recommended by someone in this forum and it is what I have done, changing the form variables and .php page names to match my own: page1.php Code: <form action="page2.php" method="post"> <p>Name:</p><input type="text" name="name" /> <input type="submit" value="Proceed to next page" /> </form> page2.php Code: <?php session_start(); $_SESSION['name'] = $_POST['name']; ?> <form action="page3.php" method="post"> <p>Age:</p><input type="text" name="age" /> <input type="submit" value="Proceed to next page" /> </form> page3.php Code: <?php session_start(); $_SESSION['age'] = $_POST['age']; ?> <form action="final.php" method="post"> <p>Profession:</p><input type="text" name="pro" /> <input type="submit" value="Send mail" /> </form> final.php Code: <?php session_start(); $name = $_SESSION['name']; $age = $_SESSION['age']; $pro = $_POST['pro']; //send mail containing above info, using mail() or whatever you prefer ?> <p>Mail send successfully!</p> First question: is the php code (session_start(); etc.) supposed to go at the beginning of the source code? Or should it be embedded in the form? Secondly, I cannot for the life of me get the sessions to work. No matter what I do, the only info that gets eventually sent to my email is that which is taken from the third form (third page, one form per page). The info from the other two forms cannot seem to carry through. Can anybody shed some light on this? Thanks yet again. Cheers, Shawn Link to comment https://forums.phpfreaks.com/topic/122965-more-help-with-sessions/ Share on other sites More sharing options...
genericnumber1 Posted September 6, 2008 Share Posted September 6, 2008 session_start() can be anywhere in the script BEFORE you use any session function/variables and BEFORE anything is outputted to the browser. Typically it is put at the top to avoid worrying about these conditions (and it's where most people look when they are reading your script.) As for it not seeming to work.... it should. Make sure you have errors set to E_ALL and go ahead and post your mail() function here (or whatever your method is) so we can see if it is an issue there. Also, be sure you have cookies enabled... Link to comment https://forums.phpfreaks.com/topic/122965-more-help-with-sessions/#findComment-635066 Share on other sites More sharing options...
PFMaBiSmAd Posted September 6, 2008 Share Posted September 6, 2008 Add the following two lines after your <?php tag on each page to see if there are any php errors being generated - ini_set ("display_errors", "1"); error_reporting(E_ALL); Link to comment https://forums.phpfreaks.com/topic/122965-more-help-with-sessions/#findComment-635070 Share on other sites More sharing options...
revraz Posted September 6, 2008 Share Posted September 6, 2008 Check your session save path in your php.ini to make sure it's a valid path. Link to comment https://forums.phpfreaks.com/topic/122965-more-help-with-sessions/#findComment-635176 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.