Hi,
I am attempting to implement an order form for a web site, using sessions to store the variables across three pages. Here's how it works:
- order.php allows the user to fill in their order. They hit the Submit button and are taken to
- confirm.php, where they can review their order. If all is well, they hit Confirm and are taken to
- thank_you.php, where the order summary is displayed so they can print it out.
So, I open a session using <?php session_start(); ?> on all three pages, as it's my understanding that is how the session variables are preserved from page to page. I'm using the following code to work the magic.
order.php
<form action="confirm2.php" method="post">
<input name="Menu_Item" type="hidden" value="Blackened Chicken" />
<input name="Menu_Date" type="hidden" value="01-01-2010" />
<input name="Main_Price" type="hidden" value="8.95" />
<input name="Keiki_Price" type="hidden" value="4.95" />
<input name="Option_Price_1" type="hidden" value="1.00" />
<input name="Option_Price_2" type="hidden" value="1.50" />
<input name="Option_Price_3" type="hidden" value="2.00" />
<table>
<tr><td>Name:</td><td><input type="text" name="Name" size="25"></td></tr>
<tr><td>E-mail</td><td><input type="text" name="E_Mail" size="25"></td></tr>
<tr><td>Contact Number:</td><td><input type="text" name="Phone_Number" size="25"> <b>* Required</b></td></tr>
<tr><td>Number of Servings:</td><td><input name="Servings" type="text" size="5" maxlength="5" /></td></tr>
<tr><td>Options:</td>
<td><select name="Option" size="1">
<option value="1">With Bread add $1.00 per serving</option>
<option value="2">With Fries add $1.50 per serving</option>
<option value="3">With Chips add $2.00 per serving</option>
</select></td>
<tr><td>Estimated Pick Up Time:</td>
<td><select name="Pick_up_Time" size="1">
<option value="4:30">4:30 PM</option>
<option value="4:45">4:45 PM</option>
<option value="5:00">5:00 PM</option>
<option value="5:15">5:15 PM</option>
<option value="5:30">5:30 PM</option>
<option value="5:45">5:45 PM</option>
<option value="6:00">6:00 PM</option>
</select></td>
</tr>
<tr><td>Number Keiki Servings:</td><td><input name="Keiki_Servings" type="text" size="5" maxlength="5" /></td></tr>
</table>
<br>
<input type="submit" value="Place Order">
<input type="reset" value="Reset">
</p>
</form>
confirm.php
<?php
if ($_POST["Option"] = 1) {
$_SESSION['base_price'] = $_POST['Main_Price'] + $_POST['Option_Price_1']; };
if ($_POST["Option"] = 2) {
$_SESSION['base_price'] = $_POST['Main_Price'] + $_POST['Option_Price_2']; };
if ($_POST["Option"] = 3) {
$_SESSION['base_price'] = $_POST['Main_Price'] + $_POST['Option_Price_3']; };
$_SESSION['total_main'] = $_SESSION['base_price'] * $_POST['Servings'];
$_SESSION['total_keiki'] = $_POST['Keiki_Servings'] * $_POST['Keiki_Price'];
$_SESSION['subtotal'] = $_SESSION['total_main'] + $_SESSION['total_keiki'];
$_SESSION['tax'] = round($_SESSION['subtotal'] * 0.04167, 2);
$_SESSION['total_due'] = $_SESSION['subtotal'] + $_SESSION['tax'];
$SESSION['Menu_Date'] = $POST_['Menu_Date'];
$SESSION['Name'] = $POST_['Name'];
$SESSION['E_Mail'] = $POST_['E_Mail'];
$SESSION['Phone_Number'] = $POST_['Phone_Number'];
$SESSION['Menu_Item'] = $POST_['Menu_Item'];
$SESSION['Servings'] = $POST_['Servings'];
$SESSION['Keiki_Servings'] = $POST_['Keiki_Servings'];
$SESSION['Pick_up_Time'] = $POST_['Pick_up_Time']
?>
<tr>
<td class="bodyText">
<p>Your order will be placed for : <span class="style9"><?php echo $_POST['Menu_Date']; ?></span></p>
<p>Order for : <span class="style9"><?php echo $_POST['Name']; ?></span></p>
<p>Contact info : <span class="style9"><?php echo $_POST['E_Mail']; ?> <?php echo $_POST['Phone_Number']; ?></span></p>
<p>Menu Item: <span class="style9"><?php echo $_POST['Menu_Item']; ?></span></p>
<p>Number of Servings: <span class="style9"><?php echo $_POST['Servings']; ?></span></p>
<p>Number of Keiki Servings: <span class="style9"><?php echo $_POST['Keiki_Servings']; ?></span></p>
<p>Subtotal: <span class="style9">$<?php echo $_SESSION['subtotal']; ?></span></p>
<p>Tax: <span class="style9">$<?php echo $_SESSION['tax']; ?></span></p>
<p>Total Due at Pick Up: <span class="style9">$<?php echo $_SESSION['total_due']; ?></span></p>
<p>Estimated Pick Up Time: <span class="style9"><?php echo $_POST['Pick_up_Time']; ?></span></p>
<form method="post" action="thank_you2.php">
<label>
<input type="submit" name="Confirm" id="Confirm" value="Confirm" />
</label>
</form>
thank_you.php
<tr><td>
<p>Order for : <span class="style9"><?php echo $_SESSION['Name']; ?></span></p>
<p>Contact info : <span class="style9"><?php echo $_SESSION['E_Mail']; ?> <?php echo $_SESSION['Phone_Number']; ?></span></p>
<p>Menu Item: <span class="style9"><?php echo $_SESSION['Menu_Item']; ?></span></p>
<p>Number of Servings: <span class="style9"><?php echo $_SESSION['Servings']; ?></span></p>
<p>Number of Keiki Servings: <span class="style9"><?php echo $_SESSION['Keiki_Servings']; ?></span></p>
<p>Subtotal: <span class="style9">$<?php echo $_SESSION['subtotal']; ?></span></p>
<p>Tax: <span class="style9">$<?php echo $_SESSION['tax']; ?></span></p>
<p>Total Due at Pick Up: <span class="style9">$<?php echo $_SESSION['total_due']; ?></span></p>
<p>Estimated Pick Up Time: <span class="style9"><?php echo $_SESSION['Pick_up_Time']; ?></span></p>
</td></tr>
Everything works well up to when I hit the Confirm button. At that point, only a couple of the variables are making it to the thank_you.php page (subtotal, tax, total). That's where I'm lost....I don't understand why the rest of the variables, which should be defined for the whole session, are not making it to the last page?!
Any assistance you can provide would be greatly appreciated.
Thanks!
Mark