/
checkout_process.php
96 lines (67 loc) · 2.56 KB
/
checkout_process.php
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
include("global.php");
include("header.php");
$first_name = $_POST["firstname"];
$address = $_POST["address"];
$city = $_POST["city"];
$state = $_POST["state"];
$zip = $_POST["zip"];
if ($first_name == "") {
$errormessage = $errormessage . "You forgot your name!<br />";
}
if ($address == "") {
$errormessage = $errormessage . "You forgot your address <br />";
}
if ($city == "") {
$errormessage = $errormessage . "You forgot your city! <br />";
}
if ($state == "") {
$errormessage = $errormessage . "You forgot your state! <br />";
}
if ($zip == "") {
$errormessage = $errormessage . "You forgot your zip code! <br />";
}
if ($errormessage != "") {
include("checkout_form.php");
die();
}
$first_name = mysqli_real_escape_string($connection,$_POST["firstname"]);
$address = mysqli_real_escape_string($connection,$_POST["address"]);
$city = mysqli_real_escape_string($connection,$_POST["city"]);
$state = mysqli_real_escape_string($connection,$_POST["state"]);
$zip = mysqli_real_escape_string($connection,$_POST["zip"]);
?>
<h1><?php echo $first_name . "'s"; ?> Reciept</h1>
<?php
echo "<div class='bold'>Address: </div>" . $address . "<br />";
echo "<div class='bold'>City: </div>" . $city . "<br />";
echo "<div class='bold'>State: </div>" . $state . "<br />";
echo "<div class='bold'>Zip Code: </div>" . $zip . "<br /><br/>";
$sql = "select products.product_name, cart.quantity, products.id
FROM products
inner join cart
on products.id=cart.product_id
WHERE session_id = '" . session_id() . "'";
$res = mysqli_query($connection,$sql) or die(mysqli_error($connection));
while ($row = mysqli_fetch_assoc($res)) {
echo $row["product_name"] . " ";
echo $row["quantity"] . "<br/>";
$sql = "update products set quantity_remaining = quantity_remaining - " . $row["quantity"] . " where id =" . $row["id"];
mysqli_query($connection,$sql) or die(mysqli_error($connection));
};
include ("jwu_email.php");
$email = "Name: " . $first_name . " Shipping Address: " . $address . " ";
$email = $email . $city . ", " . $state . " " . $zip . " ";
$sql = "select products.product_name, cart.quantity, products.id
FROM products
inner join cart
on products.id=cart.product_id
WHERE session_id = '" . session_id() . "'";
$res = mysqli_query($connection,$sql) or die(mysqli_error($connection));
while ($row = mysqli_fetch_assoc($res)) {
$email = $email . "Product Purchased: " . $row["product_name"] . " ";
$email = $email . "Quantity: " . $row["quantity"] . " ";
};
jwu_mail("smalloy01@wildcats.jwu.edu","NEW ORDER",$email);
include("footer.php");
?>