Hyperjase Posted November 17, 2011 Share Posted November 17, 2011 Hi all, I've been trying to create a page whereby a user enters a few details which is then emailed, but I'm seriously stuck on one issue. First page - console type Second page - serial number Only two steps at the moment as I need to figure it out. I'm passing everything into a variable from a post(ed) form. It appears on the next page fine, as I've been testing, but the details entered on the first page don't show on the third, however, the details from the second page do! Here is the code I have: <?php switch ($step) { case "1": ?> <table width="75%" align="center"> <tr> <td colspan="2" valign="top"> <form action="?step=2" method="post" id="consoletype">Please select your console type<br /></td></tr> <tr><td align="center" valign="top" width="50%"> <label>Xbox 360 Original (Beige or Black)<br /><img src="images/xbox360orig.gif" width="250" height="250"><br /><input class="button" type="radio" name="console" value="xboxorig" /></label></td> <td align="center" valign="top" width="50%"><label>Xbox 360 Slim<br /><img src="images/xbox360slim.gif" width="250" height="250"><br /><input type="radio" name="console" value="xboxslim" /></label></td> </tr> <tr> <td colspan="2"> <input type="submit" value="Next"> </form> </td> </tr> </table> <?php echo $code; include("footer.php"); echo $code2; include("compat.php"); echo $code3; case "2": $console = $_POST['console']; echo $console; ?> Please enter your Xbox 360 Serial Number:<br /> <form action="?step=3" method="post"> <input name="serialno" type="text" size="20" maxlength="20"> <input type="submit" value="Next"> </form> <?php echo $code; include("footer.php"); echo $code2; include("compat.php"); echo $code3; case "3": echo "<br />"; $serialno = $_POST['serialno']; echo $serialno; echo $console; echo $code; include("footer.php"); echo $code2; include("compat.php"); echo $code3; } ?> I do understand it's messy at the moment but I don't see much point beautifying everything until I can solve this problem! Cheers! Quote Link to comment https://forums.phpfreaks.com/topic/251337-variables-not-passing-beyond-one-pagestep/ Share on other sites More sharing options...
Pikachu2000 Posted November 17, 2011 Share Posted November 17, 2011 The values are only passed to the next script. If you want them to persist, you'll need to append them to the form in hidden form fields, or store them in $_SESSION vars. Quote Link to comment https://forums.phpfreaks.com/topic/251337-variables-not-passing-beyond-one-pagestep/#findComment-1289099 Share on other sites More sharing options...
Hyperjase Posted November 17, 2011 Author Share Posted November 17, 2011 Thanks for the very quick reply! I tried using $_SESSION but had exactly the same problem! What would I need to do to get them to stick within the $_SESSION? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/251337-variables-not-passing-beyond-one-pagestep/#findComment-1289100 Share on other sites More sharing options...
Pikachu2000 Posted November 17, 2011 Share Posted November 17, 2011 Every script that will use $_SESSION values needs to have session_start() called before any type of output (even whitespace) is sent to the browser, then you just assign values as you would with any other array. $_SESSION['name'] = $_POST['name']; // etc. Quote Link to comment https://forums.phpfreaks.com/topic/251337-variables-not-passing-beyond-one-pagestep/#findComment-1289104 Share on other sites More sharing options...
Hyperjase Posted November 17, 2011 Author Share Posted November 17, 2011 Thanks, quick question - am I safe putting session_start(); at the start of each case? I've put session_start(); at the very top of that script, before anything else is pulled. There is a header script included via php on this too, underneath where the session_start(); is. Think I'm following more clearly now! Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/251337-variables-not-passing-beyond-one-pagestep/#findComment-1289106 Share on other sites More sharing options...
Pikachu2000 Posted November 17, 2011 Share Posted November 17, 2011 As long as nothing is sent prior, you should be fine. If you have error reporting set up properly you should get a "headers already sent" notice otherwise. Quote Link to comment https://forums.phpfreaks.com/topic/251337-variables-not-passing-beyond-one-pagestep/#findComment-1289107 Share on other sites More sharing options...
Hyperjase Posted November 17, 2011 Author Share Posted November 17, 2011 I did get it so that I did have the headers already sent problem, cleared that up. Still not working for me though, here is the entire code: <?php session_start(); $_SESSION['console'] = $_POST['console']; $_SESSION['serialno'] = $_POST['serialno']; $step = isset($_GET['step']) ? (int)$_GET['step'] : '1'; $code ="</td></tr><tr><td colspan='6' id='footer'>"; $code2 = "</td></tr></table>"; $code3 = "</div></body></html>"; include("head.inc.php"); ?> <body id="body"> <div id="gradient"> <table id="main"> <tr> <td colspan="6" id="header"><img src="images/logo-text.gif" align="right" alt="Xbox 360 Repairs - Professional, Affordable, Guranteed" /></td> </tr> <tr> <td height="52" colspan="6" align="center" valign="top"><div id="nav"><?php include("nav.php"); ?></div></td> </tr> <tr> <td colspan="6" valign="top" id="content">Xbox 360 Registration</td> </tr> <tr> <td valign="top" id="content-register"> <?php switch ($step) { case "1": ?> <table width="75%" align="center"> <tr> <td colspan="2" valign="top"> <form action="?step=2" method="post" id="consoletype">Please select your console type<br /></td></tr> <tr><td align="center" valign="top" width="50%"> <label>Xbox 360 Original (Beige or Black)<br /><img src="images/xbox360orig.gif" width="250" height="250"><br /><input class="button" type="radio" name="console" value="xboxorig" /></label></td> <td align="center" valign="top" width="50%"><label>Xbox 360 Slim<br /><img src="images/xbox360slim.gif" width="250" height="250"><br /><input type="radio" name="console" value="xboxslim" /></label></td> </tr> <tr> <td colspan="2"> <input type="submit" value="Next"> </form> </td> </tr> </table> <?php echo $code; include("footer.php"); echo $code2; include("compat.php"); echo $code3; exit; case "2": ?> Please enter your Xbox 360 Serial Number:<br /> <form action="?step=3" method="post"> <input name="serialno" type="text" size="20" maxlength="20"> <input type="submit" value="Next"> </form> <?php echo $code; include("footer.php"); echo $code2; include("compat.php"); echo $code3; exit; case "3": echo $_SESSION['serialno']; echo "<br />"; echo $_SESSION['console']; echo $code; include("footer.php"); echo $code2; include("compat.php"); echo $code3; exit; } ?> Have I put the $_SESSION variable in the correct place? On the 3rd step it shows the serial number, from the step prior, but not the console type (first step). Thanks for your invaluable assistance! Quote Link to comment https://forums.phpfreaks.com/topic/251337-variables-not-passing-beyond-one-pagestep/#findComment-1289115 Share on other sites More sharing options...
Pikachu2000 Posted November 17, 2011 Share Posted November 17, 2011 I'm sure you're overwriting the value of $_SESSION['console'] when the form is submitted the second time. You could either move each assignment inside its respective case, or check to see if the value has already been assigned before writing it. Quote Link to comment https://forums.phpfreaks.com/topic/251337-variables-not-passing-beyond-one-pagestep/#findComment-1289121 Share on other sites More sharing options...
Hyperjase Posted November 17, 2011 Author Share Posted November 17, 2011 I did have the two session variables within each case but it still didn't appear to work, will give it a try again though, maybe I missed something! Thanks once again, Jason Quote Link to comment https://forums.phpfreaks.com/topic/251337-variables-not-passing-beyond-one-pagestep/#findComment-1289123 Share on other sites More sharing options...
Hyperjase Posted November 17, 2011 Author Share Posted November 17, 2011 Just tried placing the post to session variable at the very bottom of each respective case but when you get the step three (where both are echoed out) it shows nothing! Very confused! Quote Link to comment https://forums.phpfreaks.com/topic/251337-variables-not-passing-beyond-one-pagestep/#findComment-1289125 Share on other sites More sharing options...
Pikachu2000 Posted November 17, 2011 Share Posted November 17, 2011 Post your current code. Quote Link to comment https://forums.phpfreaks.com/topic/251337-variables-not-passing-beyond-one-pagestep/#findComment-1289139 Share on other sites More sharing options...
Hyperjase Posted November 18, 2011 Author Share Posted November 18, 2011 As this stands, this outputs only the serial number on step three, I thought I'd unset everything at the very end if possibly that had been causing issues. <?php session_start(); $_SESSION['console'] = $_POST['console']; $_SESSION['serialno'] = $_POST['serialno']; $step = isset($_GET['step']) ? (int)$_GET['step'] : '1'; $code ="</td></tr><tr><td colspan='6' id='footer'>"; $code2 = "</td></tr></table>"; $code3 = "</div></body></html>"; include("head.inc.php"); ?> <body id="body"> <div id="gradient"> <table id="main"> <tr> <td colspan="6" id="header"><img src="images/logo-text.gif" align="right" alt="Xbox 360 Repairs - Professional, Affordable, Guranteed" /></td> </tr> <tr> <td height="52" colspan="6" align="center" valign="top"><div id="nav"><?php include("nav.php"); ?></div></td> </tr> <tr> <td colspan="6" valign="top" id="content">Xbox 360 Registration</td> </tr> <tr> <td valign="top" id="content-register"> <?php switch ($step) { case "1": session_start(); ?> <table width="75%" align="center"> <tr> <td colspan="2" valign="top"> <form action="?step=2" method="post" id="consoletype">Please select your console type<br /></td></tr> <tr><td align="center" valign="top" width="50%"> <label>Xbox 360 Original (Beige or Black)<br /><img src="images/xbox360orig.gif" width="250" height="250"><br /><input class="button" type="radio" name="console" value="xboxorig" /></label></td> <td align="center" valign="top" width="50%"><label>Xbox 360 Slim<br /><img src="images/xbox360slim.gif" width="250" height="250"><br /><input type="radio" name="console" value="xboxslim" /></label></td> </tr> <tr> <td colspan="2"> <input type="submit" value="Next >>"> </form> </td> </tr> </table> <?php echo $code; include("footer.php"); echo $code2; include("compat.php"); echo $code3; exit; case "2": session_start(); ?> Please enter your Xbox 360 Serial Number:<br /> <form action="?step=3" method="post" id="serialnumber"> <input name="serialno" type="text" size="20" maxlength="20"> <br /> <input type="submit" value="Next >>"> </form> <?php echo $code; include("footer.php"); echo $code2; include("compat.php"); echo $code3; exit; case "3": session_start(); echo $_SESSION['console']; echo "<br />"; echo $_SESSION['serialno']; session_unregister("console"); session_unregister("serialno"); session_destroy(); ?><br /><br /><a href="?step=1">Start Over</a><?php echo $code; include("footer.php"); echo $code2; include("compat.php"); echo $code3; exit; } ?> When I move "$_SESSION['console'] = $_POST['console']; & $_SESSION['serialno'] = $_POST['serialno'];" into the respective areas where they are submitted, nothing shows on step 3! Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/251337-variables-not-passing-beyond-one-pagestep/#findComment-1289211 Share on other sites More sharing options...
Hyperjase Posted November 18, 2011 Author Share Posted November 18, 2011 I've managed to get it working, I moved each session to post variable inside the step after it's entered, then it all shows on the last page, dont quite know either why I hadn't worked before or why I'd made such a schoolboy error! Thanks for your help on this one! Quote Link to comment https://forums.phpfreaks.com/topic/251337-variables-not-passing-beyond-one-pagestep/#findComment-1289413 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.