forked from johhar-7/D0018E_Lab_G11
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremovefromcart.php
More file actions
44 lines (34 loc) · 978 Bytes
/
removefromcart.php
File metadata and controls
44 lines (34 loc) · 978 Bytes
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
<html>
<head>
</head>
<body>
<?php
$uID = intval($_GET['a']);
$pID = intval($_GET['b']);
$pQ = intval($_GET['c']);
$servername = "localhost";
$username = "root";
$password = "d0018eServer!";
$dbname = "store";
$dbname2 = "user";
$conn = new mysqli($servername, $username, $password, $dbname);
$conn2 = new mysqli($servername, $username, $password, $dbname2);
mysqli_select_db($conn2, "cart_test");
$sql = "SELECT id, Product_ID, quantity FROM cart WHERE id = '".$uID."' AND Product_ID = '".$pID."'";
$result = $conn2->query($sql);
$row = $result->fetch_assoc();
if($row['quantity'] == 1){
// subtract from quantity
$sql = "DELETE FROM cart WHERE id = '".$uID."' AND Product_ID = '".$pID."'";
$conn2->query($sql);
}
else{
// remove from cart
$sql = "UPDATE cart SET quantity = quantity - 1 WHERE id = '".$uID."' AND Product_ID = '".$pID."'";
$conn2->query($sql);
}
$conn->close();
$conn2->close();
?>
</body>
</html>