Jump to content

Variables not passing beyond one page/step


Hyperjase

Recommended Posts

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!

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.