Code: Select all
function process_order()
{
// Get order form variables
$comments = $_REQUEST['comments'];
$order_total = $_REQUEST['order_total'];
$card_type = $_REQUEST['card_type'];
$card_name = $_REQUEST['card_name'];
$card_number = $_REQUEST['card_number'];
$card_expiration_date = $_REQUEST['card_expiration_date'];
$card_ccv_number = $_REQUEST['card_ccv_number'];
$username = $_SESSION['username'];
$sql = "SELECT customer_id FROM customer_name WHERE username = '".$username."'";
$result = mysql_query($sql);
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$customer_id = $row['customer_id'];
$order_time = date('Y-m-d h:i a');
$check_order_time = $order_time;
$order_string = $_SESSION['lineItems_in_cart'];
if($order_string != '')
{
// Connect to DB
$db = new DATABASE;
$db->db('connect');
// insert payment information
$result = mysql_query("INSERT INTO `payment`
(customer_id, payment_type, payment_amount, card_type, card_name, card_number, card_expiration, card_ccv_number, date)
VALUES
(\"$customer_id\", 'cc', \"$order_total\", \"$card_type\", \"$card_name\", \"$card_number\",
\"$card_expiration_date\", \"$card_ccv_number\", \"$order_time\")");
$payment_id = mysql_insert_id();
// Get cart weight
$total_weight = $this->get_cart_weight();
// insert order information
$result = mysql_query("INSERT INTO `orders`
(customer_id, payment_id, order_string, order_total, order_weight, order_status, comments, date)
VALUES
(\"$customer_id\", \"$payment_id\", \"$order_string\", \"$order_total\", \"$total_weight\", 'Pending',
\"$comments\", \"$order_time\")");
$order_id = mysql_insert_id();
//original insert order line
//$sql = "INSERT INTO `orders`
//(customer_id, payment_id, order_string, order_total, order_weight, order_status, comments, date)
//VALUES
//(\"$customer_id\", \"$payment_id\", \"$order_string\", \"$order_total\", \"$total_weight\", 'Pending',
//\"$comments\", \"$order_time\")";
//$result = mysql_query($sql);
//$order_id = mysql_insert_id();
$cart_lineItems = $this->get_cart();
$cart_lineItem_count = count($cart_lineItems);
$i = 0;
$lineItem_id = 1;
while ($i < $cart_lineItem_count)
{
$lineitems = explode("~", $cart_lineItems[$i]);
$product_id = $lineitems[0];
$quantity = $lineitems[1];
$ship_to = $lineitems[2];
$sql = "INSERT INTO `line_item`
(lineitem_id, order_id, product_id, ship_to, customer_id, quantity)
VALUES
(\"$lineitem_id\", \"$order_id\", \"$product_id\", \"$ship_to\", \"$customer_id\",
\"$quantity\")";
$result = mysql_query($sql);
//echo "sql: ".$sql."<br>";
$lineItem_id++;
$i++;
}
//exit;
// Unload the cart
unset($_SESSION['lineItems_in_cart']);
//print $orderinfo;
print "<p CLASS=\"clsP\">Thank you for submitting your order. Feel free to continue to use the site, just remember to <A HREF='index.php?page=logout' >Logout</A> when you are finished!</p>";
}
else
{
print "<p CLASS=\"clsP\">There is nothing in your cart to process!</p>";
}
}Thanks.