Jump to content

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!

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.

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.

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!

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!

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.

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!

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!

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.