-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcart.php
More file actions
92 lines (88 loc) · 3.19 KB
/
cart.php
File metadata and controls
92 lines (88 loc) · 3.19 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
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
<?php
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>LuLa Shop</title>
<?php include 'menu.php'; ?>
<link rel="stylesheet" href="http://www.w3schools.com/lib/w3.css">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<?php
//TODO: create account for this app
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "lulashop";
// Connect to the database
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e) {
echo "Connection failed: " . $e->getMessage();
die();
}
?>
</head>
<body>
<?php
if(isset($_SESSION["userType"])){
echo "gate 0";
$userType = $_SESSION["userType"];
$user = $_SESSION["userID"];
if (isset($_POST["submit"])) {
$sku = $_POST["sku"];
$sql = "SELECT * FROM `inventory` WHERE `sku` = ".$sku;
$conn->beginTransaction();
$pdo = $conn->query($sql);
$result = $pdo->fetch();
$sku = $_POST["sku"];
echo "gate 1";
if ($_POST["submit"]=="REMOVE ITEM") {
$conn->exec("UPDATE `inventory`
SET `quantity` = $result[quantity] + 1
WHERE sku = $sku;");
$conn->exec("DELETE FROM cart WHERE sku = $sku AND userID = $user;");
$conn->commit();
}
}
echo "<h3>Items in Cart</h3>";
$sql = "SELECT `inventory`.`sku`,`inventory`.`category`,`member`.`firstName`,`member`.`lastName`
FROM `inventory`,`cart`,`member`
WHERE `cart`.`userID` =".$user."
AND `inventory`.`sku`=`cart`.`sku`
AND `member`.`memberID` = `inventory`.`memberID`";
echo "<br>".$sql."<br>";
$pdo = $conn->query($sql);
echo "<table class=\"w3-striped\">";
echo "<tr><th>Style</th><th>Seller</th><th>Name</th><th> </th><th> </th><tr>";
while($cart = $pdo->fetch()){
$sql2 = "SELECT `picURL` FROM `picture` WHERE `sku`=".$cart["sku"];
$pdo2 = $conn->query($sql2);
echo "<tr>";
while($pic = $pdo2->fetch()){
echo "<td><div class=\"w3-card-8\"><img src=\"".$pic["picURL"]."\" width=\"300\" height=\"300\"></div></td>";
}
echo "</tr>";
echo "<tr><td>".$cart["category"]."</td><td>".$cart["firstName"]."</td><td>".$cart["lastName"]."</td>";
echo "<td><form method=\"post\" action=\"cart.php\" target=\"_self\">";
echo "<button style='font-size:24px' type='submit' value='REMOVE ITEM' name='submit'>Remove Item<i class='material-icons'>remove_shopping_cart</i></button>";
echo "<input type=\"number\" name=\"sku\" hidden value=\"".$cart["sku"]."\">";
echo "</td></form></tr>";
}
echo "</table>";
echo "<div class='w3-container w3-card'>";
echo "<form method='post' action='invoice.php'>";
echo "<button class='w3-button' style='font-size:24px' type='submit' name='checkout' value='checkout'>Checkout<i class='material-icons'>shopping_cart</i></button>";
echo "</form></div>";
}
$conn = null;
?>
</body>
<footer>
<?php include 'foot.php'; ?>
</footer>
</html>