This site offers online ordering for what is ultimately a PDF form.
Here is the flow of the pages:
Login (no sessions) => Place Order => Confirm Order (start sessions)
On the Place Order page, I have the field order_no that is auto incremented by MySQL.
What I can't get is for the order number to appear on the confirmation page.
Here is the Place Order code:
Code: Select all
<p class="heading">Online Order Form</p>
<p class="navtext">Please fill in your order details below.</p>
<?php
ini_set('display_errors', 1); //Handle errors
error_reporting (E_ALL & ~E_NOTICE);
if (isset($_POST['submit'])) { //Handle form
session_name('PlaceOrder'); //Start session
session_start();
header("Cache-control: private"); // IE 6 Fix
//Connect and select
if ($dbc = @mysql_connect ('localhost', 'user', 'password'))
{
if (!@mysql_select_db ('db')) {
die ('<p>Could not select the database because: <b>' . mysql_error() . '</b></p>');
}
} else {
die ('<p>Could not connect to MySQL because: <b>' . mysql_error() . '</b></p>');
}
//Define query
$query1 = "INSERT INTO orders (order_no, order_date, collateral_owner, collateral_address,
collateral_city, collateral_state, collateral_zip, collateral_county, collateral_twp,
legal_descr, loan_no, lender_name, lender_address, lender_city, lender_state, lender_zip,
lender_phone, lender_fax, lender_id) VALUES (0, NOW(),
'{$_POST['collateral_owner']}', '{$_POST['collateral_address']}', '{$_POST['collateral_city']}',
'{$_POST['collateral_state']}', '{$_POST['collateral_zip']}', '{$_POST['collateral_county']}',
'{$_POST['collateral_twp']}', '{$_POST['legal_descr']}', '{$_POST['loan_no']}'
'{$_POST['lender_name']}', '{$_POST['lender_address']}', '{$_POST['lender_city']}',
'{$_POST['lender_state']}', '{$_POST['lender_zip']}', '{$_POST['lender_phone']}',
'{$_POST['lender_fax']}', '{$_POST['lender_id']}')"; ?>
<?php
//Execute query
if (@mysql_query ($query1)) {
echo '<p>Thank you for your order. You will receive a confirmation.</p>';
} else {
echo "<p>We're sorry but your order could not be placed because:
<b>" . mysql_error() . "</b>. Please report this error to Michigan Flood Maps.</p>";
}
mysql_close();
}
//Display the form
?>
<form action="temp-confirm.php" method="post" name="orderform">
<table width="425" border="0" align="center" cellpadding="1" cellspacing="2">
<tr class="navtext">
<td width="200" class="navtext" valign="top"><b class="heading">Today's
Date</b></td>
<td>
<input name="order_date" type="text" class="navtext" id="order_date">
<br>
yyyy-mm-dd </td>
</tr>
<tr class="navtext">
<td colspan="2"><b class="heading">Lender Information</b></td>
</tr>
<tr class="navtext">
<td valign="top">Lender ID # </td>
<td valign="top">
<input name="lender_id" type="text" class="navtext" id="lender_id">
</td>
</tr>
<tr class="navtext">
<td valign="top">Lender Name</td>
<td valign="top">
<input name="lender_name" type="text" class="navtext" id="lender_name">
</td>
</tr>
<tr class="navtext">
<td valign="top">Lender Address </td>
<td valign="top">
<input name="lender_address" type="text" class="navtext" id="lender_address">
</td>
</tr>
<tr class="navtext">
<td valign="top">City</td>
<td valign="top">
<input name="lender_city" type="text" class="navtext" id="lender_city">
</td>
</tr>
<tr class="navtext">
<td class="navtext" valign="top">State</td>
<td valign="top">
<input name="lender_state" type="text" class="navtext" id="lender_state" value="MI" size="10" maxlength="10">
</td>
</tr>
<tr class="navtext">
<td valign="top">Zip</td>
<td valign="top">
<input name="lender_zip" type="text" class="navtext" id="lender_zip" size="10" maxlength="10">
</td>
</tr>
<tr class="navtext">
<td valign="top">Phone<br>
###-###-#### </td>
<td valign="top">
<input name="lender_phone" type="text" class="navtext" id="lender_phone">
</td>
</tr>
<tr class="navtext">
<td valign="top">Fax<br>
###-###-#### </td>
<td valign="top">
<input name="lender_fax" type="text" class="navtext" id="lender_fax">
</td>
</tr>
<tr class="navtext">
<td class="navtext" valign="top"> </td>
<td class="navtext" valign="top"> </td>
</tr>
<tr class="navtext">
<td colspan="2" valign="top">
<hr width="70%" size="1" color="#666666">
</td>
</tr>
<tr class="navtext">
<td colspan="2" valign="top"><b class="heading">Property Information</b></td>
</tr>
<tr class="navtext">
<td valign="top">Loan ID # </td>
<td valign="top">
<input name="loan_no" type="text" class="navtext" id="loan_no">
</td>
</tr>
<tr class="navtext">
<td valign="top">Owner Name</td>
<td valign="top">
<input name="collateral_owner" type="text" class="navtext" id="collateral_owner">
</td>
</tr>
<tr class="navtext">
<td valign="top">Property Address </td>
<td valign="top">
<input name="collateral_address" type="text" class="navtext" id="collateral_address">
</td>
</tr>
<tr class="navtext">
<td valign="top">City</td>
<td valign="top">
<input name="collateral_city" type="text" class="navtext" id="collateral_city2">
</td>
</tr>
<tr class="navtext">
<td class="navtext" valign="top">State</td>
<td valign="top">
<input name="collateral_state" type="text" class="navtext" id="collateral_state" value="MI" size="10" maxlength="10">
</td>
</tr>
<tr class="navtext">
<td valign="top">Zip</td>
<td valign="top">
<input name="collateral_zip" type="text" class="navtext" id="collateral_zip" size="10" maxlength="10">
</td>
</tr>
<tr class="navtext">
<td valign="top">County</td>
<td valign="top">
<input name="collateral_county" type="text" class="navtext" id="collateral_county">
</td>
</tr>
<tr class="navtext">
<td valign="top">Township (if applicable)</td>
<td valign="top">
<input name="collateral_twp" type="text" class="navtext" id="collateral_twp">
</td>
</tr>
<tr class="navtext">
<td valign="top">Legal Description<span class="smallbodytext"> (optional)</span></td>
<td valign="top"> </td>
</tr>
<tr class="navtext">
<td colspan="2" valign="top">
<textarea name="legal_descr" cols="50" id="legal_descr"></textarea>
</td>
</tr>
<tr>
<td colspan="2">
<div align="center">
<input type="submit" name="submit" value="Place Order" class="smallbodytext">
</div>
</td>
</tr>
</table>
</form><p class="navtext"> </p>
</table>
</body>
</html>Here is the Confirm Order code:
Code: Select all
<?php session_start();
header("Cache-control: private"); //IE 6 fix
?>
<p class="heading">Confirming Your Order</p>
<?php
// Get values from form
$orderno = trim($_POST['order_no']);
$orderdate = trim($_POST['order_date']);
$loanno = trim($_POST['loan_no']);
$cowner = trim($_POST['collateral_owner']);
$caddress = trim($_POST['collateral_address']);
$ccity = trim($_POST['collateral_city']);
$cstate = trim($_POST['collateral_state']);
$czip = trim($_POST['collateral_zip']);
$ccounty = trim($_POST['collateral_county']);
$ctwp = trim($_POST['collateral_township']);
$lname = trim($_POST['lender_name']);
$laddress = trim($_POST['lender_address']);
$lcity = trim($_POST['lender_city']);
$lstate = trim($_POST['lender_state']);
$lzip = trim($_POST['lender_zip']);
$lphone = trim($_POST['lender_phone']);
$lfax = trim($_POST['lender_fax']);
$lenderid = trim($_POST['lender_id']);
// validate/test the data
if (strlen($orderno) < 1 || strlen($orderdate) < 1 || strlen($loanid) < 1 || strlen($cowner) < 1
|| strlen($caddress) < 1 || strlen($ccity) < 1 || strlen($cstate) < 1 || strlen($czip) < 1
|| strlen($ccounty) < 1 || strlen($lname) < 1 || strlen($laddress) < 1 || strlen($lcity) < 1
|| strlen($lstate) < 1 || strlen($lphone) < 1 || strlen($lfax) < 1 || strlen($lenderid) < 1){
// take corrective action
echo "You have left one or more required fields empty. <br />
Please click your browser's BACK button to complete the form.";
}
else
{
// do whatever with the data
}
?>
<table width="425" border="0" align="center" cellpadding="1" cellspacing="2">
<tr class="navtext">
<td height="25" class="navtext"><b class="heading">Order Date </b></td>
<td>
<?php echo $orderdate; ?>
</td>
</tr>
<tr class="navtext">
<td height="25" class="navtext"><b class="heading">Order Number</b></td>
<td><?php //echo $orderno; ?></td>
</tr>
<tr class="navtext">
<td width="40%" valign="top" class="navtext"><b class="heading">Lender Information</b></td>
<td><p><?php echo $lname; ?><br />
<?php echo $laddress; ?><br />
<?php echo $lcity; ?>, <?php echo $lstate; ?> <?php echo $lzip; ?><br />
Lender Id: <?php echo $lenderid; ?></p>
<p> </p></td>
</tr>
<tr class="navtext">
<td valign="top" class="navtext"><b class="heading">Property Information </b></td>
<td>Loan number: <?php echo $loanno; ?><br>
Owner: <br />
<?php echo $cowner; ?><br />
<?php echo $caddress; ?><br />
<?php echo $ccity; ?>, <?php echo $cstate; ?> <?php echo $czip; ?><br />
<?php echo $ccounty; ?><br />
<?php echo $ctwp; ?><br />
<?php echo $clegal; ?></td>
</tr>
</table>
<?php
// store all the user defined variables into an array
$my_vars = get_defined_vars ($orderno, $orderdate, $loanid, $cowner, $caddress, $ccity, $cstate, $czip, $ccounty, $ctwp, $clegal);
// store the array into the session
$_SESSION['my_vars'] = $my_vars;
// proceed to the next page
?>
</body>
</html>
<?php
mysql_free_result($query1);
?>Code: Select all
<?php
// store all the user defined variables into an array
$my_vars = get_defined_vars ($orderno, $orderdate, $loanid, $cowner, $caddress, $ccity, $cstate, $czip, $ccounty, $ctwp, $clegal);
// store the array into the session
$_SESSION['my_vars'] = $my_vars;
// proceed to the next page
?>