<html>
<!-- checkout_completed.php - completing the checkout for this
order -->
<head><title>Completing the Checkoutder</title></head>
<?php
include("includes/header.php");
include("includes/connection_config.php");
// we assign $_SESSION variables to local
variables
// while this probably isn't necessary, it makes some processing
look cleaner
// we need these values to compute the shipping and taxes
session_start();
$id_basket = $_SESSION['id_basket'];
$sub_total = $_SESSION['total_cost'];
$total_weight = $_SESSION['total_weight'];
$ship_state = $_SESSION["ship_state"];
$order_placed = 1;
// initializing a variable that tells
whether the weight was found in the ranges in the table
$in_table = "not_found";
// now we need to compute the shipping
charges
// first we need to find the shipping charges in the table based
on the weight
// if the weight is greater than that contained in the table
then we need to use the formula
// first we need to connect to the shipping table
// connecting to the database on
battcave.com
$link = mysql_connect($host, $user, $password);
// creating the query string
$ship_query_string = "SELECT * FROM shipping";
// executing the SQL statement
$ship_result_set = mysql_db_query($db_name, $ship_query_string,
$link);
// looping through the entries in the
resultset to determine shipping charges
while ($row = mysql_fetch_array($ship_result_set))
{
if (($total_weight >= $row[lower_limit]) && ($total_weight
<= $row[upper_limit]))
{
$in_table = "found";
$shipping_cost = $row[shipping_cost];
}
}
// if the weight is too large to be
contained in the table we need to
// compute the shipping using the formula
if ($in_table == "not_found")
{
$shipping_cost = 5.00 + (0.5 * $total_weight);
}
$shipping_cost = round($shipping_cost,2);
// now we need to determine if there are
any taxes to be charged
// based on the $ship_state
// first we need to develop another query to access the state
tax rate
$tax_query_string = "SELECT * FROM taxes_state WHERE state_name
= '$ship_state'";
// now we need to create the resultset
$tax_result_set = mysql_db_query($db_name, $tax_query_string,
$link);
// looping through the entries in the
resultset to determine taxes
while ($row_tax = mysql_fetch_array($tax_result_set))
{
$tax = $row_tax[tax_rate] * $sub_total;
$tax = round($tax,2);
$sub_total = round($sub_total,2);
$overall_cost = $sub_total + $tax + $shipping_cost;
$overall_cost = round($overall_cost,2);
}
// now we want to update our values in the
basket
$update_query_string = "UPDATE basket SET
order_placed = $order_placed,
sub_total = $sub_total,
total =$overall_cost,
cost_shipping = $shipping_cost,
tax =$tax
WHERE (id_basket = $id_basket)";
// performing the update
mysql_db_query($db_name, $update_query_string, $link);
// now we want to retrive the order_number
for the order
// get the id_order_data from the session
variable
// put it into a local variable for display
$order_number = $_SESSION["id_order_data"];
?>
<br><br>
<table border="0" align="center">
<tr>
<td align="right"><font size="4" color="a66838">Your order
number is:</font>
</td>
<td align="right"><font size="4" color="c0c0c0"><?php echo $order_number;
?></font>
</td>
</tr>
<tr>
<td align="right"> </td>
<td align="right"></td>
</tr>
<tr>
<td align="right"><font size="4" color="a66838">The subtotal
is:</font>
</td>
<td align="right"><font size="4" color="c0c0c0">$<?php printf("%01.2f",$sub_total);
?></font>
</td>
</tr>
<tr>
<td align="right"><font size="4" color="a66838">The tax
is:</font>
</td>
<td align="right"><font size="4" color="c0c0c0">$<?php printf("%01.2f",$tax);
?></font>
</td>
</tr>
<tr>
<td align="right"><font size="4" color="a66838">The shipping
costs:</font>
</td>
<td align="right"><font size="4" color="c0c0c0">$<?php printf("%01.2f",$shipping_cost);
?></font>
</td>
</tr>
<tr>
<td align="right"> </td>
<td align="right"></td>
</tr>
<tr>
<td align="right"><font size="4" color="a66838">The total cost
is:</font>
</td>
<td align="right"><font size="4" color="c0c0c0"><b>$<?php printf("%01.2f",$overall_cost);
?></b></font>
</td>
</tr>
</table>
<?php
// closing the link to the database
mysql_close($link);
?>
</body>
</html> |