-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckout.php
More file actions
59 lines (44 loc) · 1.68 KB
/
Copy pathcheckout.php
File metadata and controls
59 lines (44 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
session_start();
include_once("includes/template_header.php");
if ( isset( $_GET['total']) && ($_GET['total'] > 0 ) && (!empty($_SESSION['cart'])))
{
require ( 'connect_db.php' ) ;
$fname = $_POST['f_name'];
$lname = $_POST['l_name'];
$email = $_POST['email'];
$telephone = $_POST['telephone'];
$address = $_POST['address'];
$postcode = $_POST['postcode'];
$country = $_POST['country'];
$q = "INSERT INTO customer (f_name, l_name, email, telephone, address, postcode, country, date_added)
VALUES ('$fname', '$lname', '$email', '$telephone', '$address', '$postcode', '$country', NOW())";
$r = mysqli_query ( $dbc, $q );
$customer_id = mysqli_insert_id( $dbc );
$q = "INSERT INTO customerorders ( total, date_added, user_id ) VALUES (".$_GET['total'].", NOW(), ".$customer_id.")";
$r = mysqli_query ( $dbc, $q );
$order_id = mysqli_insert_id( $dbc );
$q = "SELECT * FROM products WHERE id IN (" ;
foreach ( $_SESSION['cart'] as $id => $value )
{ $q .= $id . ',' ;}
$q = substr( $q, 0, -1) . ') ORDER BY id ASC';
$r = mysqli_query ($dbc, $q);
while ( $row = mysqli_fetch_array ( $r, MYSQLI_ASSOC))
{
$query = "INSERT INTO ordercontents (order_id, product_id, quantity, price) VALUES ( $order_id, ".$row['id'].",".
$_SESSION['cart'][$row['id']]['quantity'].",".
$_SESSION['cart'][$row['id']]['price'].")";
$result = mysqli_query ($dbc, $query);
}
//$q = "UPDATE products SET stock_level = stock_level - 1 WHERE id = '$id'";
//$result = mysqli_query ($dbc, $query);
mysqli_close ($dbc);
echo "<p> Thanks for your order. Your order number is: ".$order_id."</p>";
$_SESSION['cart'] = NULL;
}
else
{echo '<p>There are no items in your cart.</p>';}
?>
<?php
include_once("includes/template_footer.php");
?>