Solarpitch Posted January 6, 2008 Share Posted January 6, 2008 Hey, I'm currently using this code to assign form details to session variables, then on the second piece of code I am trying to echo the value of the session variables but noting will print to screen. Here's an example of what I am trying.. // Get details from form and assign to session - then move to step 2 <?php session_start(); $process = isset($_POST['process']) ? $_POST['process'] : ''; if ($process != "execute") { //not being submitted... } else { $firstname = $_POST['firstname']; $_SESSION['firstname'] = $firstname; $lastname = $_POST['lastname']; $_SESSION['lastname'] = $lastname; $email = $_POST['email']; $_SESSION['email'] = $email; header("Location:step2.php"); ?> } // This is the code on the other page where I am trying to display the session values... <?php session_start(); echo $_SESSION['firstname']; echo $_SESSION['lastname']; echo $_SESSION['email']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/84790-solved-session-question/ Share on other sites More sharing options...
redarrow Posted January 6, 2008 Share Posted January 6, 2008 post the form? Quote Link to comment https://forums.phpfreaks.com/topic/84790-solved-session-question/#findComment-432195 Share on other sites More sharing options...
Ken2k7 Posted January 6, 2008 Share Posted January 6, 2008 Is the bottom code step2.php? Quote Link to comment https://forums.phpfreaks.com/topic/84790-solved-session-question/#findComment-432197 Share on other sites More sharing options...
teng84 Posted January 6, 2008 Share Posted January 6, 2008 i believe if your error reporting is on you should get a warning message saying header already sent etc... your session start should be at the top most of the page right after the declaration of php Quote Link to comment https://forums.phpfreaks.com/topic/84790-solved-session-question/#findComment-432199 Share on other sites More sharing options...
PFMaBiSmAd Posted January 6, 2008 Share Posted January 6, 2008 Judging from the appearance of the posted code, you have multiple newlines at the start of each file before the first <?php tag. These are content that are output to the browser and prevent the session from starting, on both pages. New lines after the <?php tag are not content and are not output to the browser, unless specifically echoed using php code. Quote Link to comment https://forums.phpfreaks.com/topic/84790-solved-session-question/#findComment-432203 Share on other sites More sharing options...
Solarpitch Posted January 6, 2008 Author Share Posted January 6, 2008 There are 5 steps pages, each with different forms that gather different user info. I am storing all user details from the forms into a session, then on Step5.php I want to display all of the session details so the user can confirm the form. Here's the form from Step1.php teng84 - I tried that but still no joy <form name="form1" method="post" action="step1.php"> <table width="563" border="0" cellspacing="2" cellpadding="0"> <tr> <td> </td> <td width="419"> </td> </tr> <tr> <td width="138"><div align="right" class="style55">First name:</div></td> <td><input name="firstname" type="text" id="firstname" style="width:200px; height:15px; " value="<?print $firstname; ?>"> <span class="style69">*</span></td> </tr> <tr> <td><div align="right" class="style55">Last name:</div></td> <td><input name="lastname" type="text" id="lastname" style="width:200px; height:15px; " value="<?print $lastname; ?>"> <span class="style69">*</span></td> </tr> <tr> <td><div align="right" class="style55">Email address:</div></td> <td><input name="email" type="text" id="email" style="width:200px; height:15px; " value="<?print $email; ?>"> <span class="style69">*</span></td> </tr> <tr> <td><div align="right" class="style55">Confirm email address </div></td> <td><input name="cemail" type="text" id="cemail" style="width:200px; height:15px; " value="<?print $cemail; ?>"> <span class="style69">*</span></td> </tr> <tr> <td><div align="right" class="style55">Contact number:</div></td> <td><input name="contact_no" type="text" id="contact_no" style="width:200px; height:15px; " value="<?print $contact_no; ?>"></td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td><div align="right" class="style55">Username</div></td> <td><input name="username" type="text" id="username" style="width:200px; height:15px; " value="<?print $username; ?>"> <span class="style69">*</span></td> </tr> <tr> <td><div align="right" class="style55">Password:</div></td> <td><input name="password" type="password" id="password" style="width:200px; height:15px; " value="<?print $password; ?>"> <span class="style69">*</span></td> </tr> <tr> <td><div align="right" class="style55">Confirm Password:</div></td> <td><input name="cpassword" type="password" id="cpassword" style="width:200px; height:15px; " value="<?print $cpassword; ?>"> <span class="style69">*</span></td> </tr> </table> <div align="right"> <input type="hidden" name="process" value="execute"> <input type="submit" name="Submit" value="Next >>"> </div> </form> Quote Link to comment https://forums.phpfreaks.com/topic/84790-solved-session-question/#findComment-432205 Share on other sites More sharing options...
Solarpitch Posted January 6, 2008 Author Share Posted January 6, 2008 Judging from the appearance of the posted code, you have multiple newlines at the start of each file before the first <?php tag. These are content that are output to the browser and prevent the session from starting, on both pages. New lines after the <?php tag are not content and are not output to the browser, unless specifically echoed using php code. Thats only in the above example but this isnt the case on my page itself. Quote Link to comment https://forums.phpfreaks.com/topic/84790-solved-session-question/#findComment-432207 Share on other sites More sharing options...
redarrow Posted January 6, 2008 Share Posted January 6, 2008 try that if it works then it a header problam / whight spaces......... <?php ob_start(); session_start(); $process = isset($_POST['process']) ? $_POST['process'] : ''; if ($process != "execute"){ }else{ $firstname = $_POST['firstname']; $_SESSION['firstname'] = $firstname; $lastname = $_POST['lastname']; $_SESSION['lastname'] = $lastname; $email = $_POST['email']; $_SESSION['email'] = $email; header("Location:step2.php"); ob_flush(); } ?> <?php ob_start(); session_start(); echo $_SESSION['firstname']; echo $_SESSION['lastname']; echo $_SESSION['email']; ob_flush(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/84790-solved-session-question/#findComment-432209 Share on other sites More sharing options...
Solarpitch Posted January 6, 2008 Author Share Posted January 6, 2008 Thats still doesnt work I am afraid. Would I need to include ob_start() on the page that I am calling the session to display also. (I am offline after this post, but I'll check back later.. thanks for the help guys) Quote Link to comment https://forums.phpfreaks.com/topic/84790-solved-session-question/#findComment-432211 Share on other sites More sharing options...
redarrow Posted January 6, 2008 Share Posted January 6, 2008 you need to try the format as posted on all pages with no whight gaps and try ob_start() and ob_flush()..... Quote Link to comment https://forums.phpfreaks.com/topic/84790-solved-session-question/#findComment-432212 Share on other sites More sharing options...
Ken2k7 Posted January 6, 2008 Share Posted January 6, 2008 Shouldn't it be $_POST['submit'] and not $_POST['process'] ? Quote Link to comment https://forums.phpfreaks.com/topic/84790-solved-session-question/#findComment-432217 Share on other sites More sharing options...
redarrow Posted January 6, 2008 Share Posted January 6, 2008 no but if($_POST['submit']){ } might do it......... Quote Link to comment https://forums.phpfreaks.com/topic/84790-solved-session-question/#findComment-432219 Share on other sites More sharing options...
teng84 Posted January 6, 2008 Share Posted January 6, 2008 the other form is set as hidden so if submit is set process will also be set right? Quote Link to comment https://forums.phpfreaks.com/topic/84790-solved-session-question/#findComment-432221 Share on other sites More sharing options...
redarrow Posted January 6, 2008 Share Posted January 6, 2008 looks good to me but why did he have it not there no need for the ternary op || or good enough? <?php ob_start(); session_start(); $process =(isset($_POST['submit']) || $_POST['process'] ) ; if ($process != "execute"){ }else{ $firstname = $_POST['firstname']; $_SESSION['firstname'] = $firstname; $lastname = $_POST['lastname']; $_SESSION['lastname'] = $lastname; $email = $_POST['email']; $_SESSION['email'] = $email; header("Location:step2.php"); ob_flush(); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/84790-solved-session-question/#findComment-432226 Share on other sites More sharing options...
PFMaBiSmAd Posted January 7, 2008 Share Posted January 7, 2008 Please check your web server log for the errors that are preventing the session from working. Until you know why they are failing, adding and changing code is pointless. Quote Link to comment https://forums.phpfreaks.com/topic/84790-solved-session-question/#findComment-432241 Share on other sites More sharing options...
Solarpitch Posted January 8, 2008 Author Share Posted January 8, 2008 Hey guys, Just to let you know.. the session seemed to work when I used isset to check if the variable was set, then if it was assign the value to the session - and this works fine... $firstname = $_POST['firstname']; if(isset($firstname)) {$_SESSION['firstname'] = $firstname;} Quote Link to comment https://forums.phpfreaks.com/topic/84790-solved-session-question/#findComment-433849 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.