-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathajax_crud.php
executable file
·88 lines (67 loc) · 2.91 KB
/
ajax_crud.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
<?php
include 'config/database.php';
$json = file_get_contents('php://input');
$postdata = json_decode($json);
$category = $postdata->category;
echo $category;
if (isset($category) == 'AddItem') {
echo $postdata->cart_item_add;
if (isset($postdata->cart_item_add)) {
$cartId = $postdata->cart_item_add;
echo $cartId;
$checkCart = mysqli_query($connection,'select * from cart_table where cart_id = "'.$cartId.'"');
$productRecords = mysqli_query($connection,'select * from products where id = "'.$cartId.'"');
if (mysqli_num_rows($checkCart) > 0) {
$quantity = 1;
foreach ($checkCart as $cart) {
$quantity += $cart['cart_quantity'];
}
$insert = mysqli_query($connection,'update cart_table set cart_quantity = "'.$quantity.'" where cart_id = "'.$cartId.'"');
}
else {
foreach ($productRecords as $record) {
$insert = mysqli_query($connection,'insert into cart_table values(0,"'.$cartId.'","'.$record['name'].'","'.$record['details'].'","'.$record['price'].'",1,"'.$record['images'].'")');
}
}
}
}
if (isset($category) == 'UpdateItem') {
if (isset($postdata->cart_item_add)) {
$cartId = $postdata->cart_item_add;
$checkCart = mysqli_query($connection, 'select * from cart_table where id = "'.$cartId.'"');
if (mysqli_num_rows($checkCart) > 0) {
$quantity = 1;
foreach ($checkCart as $cart) {
$quantity += $cart['cart_quantity'];
}
echo $quantity;
$insert = mysqli_query($connection, 'update cart_table set cart_quantity = "'.$quantity.'" where id = "'.$cartId.'"');
}
}
}
if (isset($category) == "SubtractItem") {
if (isset($postdata->cart_item_subtract)) {
$cartId = $postdata->cart_item_subtract;
$checkCart = mysqli_query($connection, 'select * from cart_table where id = "'.$cartId.'"');
if (mysqli_num_rows($checkCart) > 0) {
$quantity = 1;
foreach ($checkCart as $cart) {
$quantity = $cart['cart_quantity'] - $quantity;
if($cart['cart_quantity'] > 1) {
$insert = mysqli_query($connection, 'update cart_table set cart_quantity = "'.$quantity.'" where id = "'.$cartId.'"');
}
else {
$delete_item_cart = mysqli_query($connection, 'delete from cart_table where id = "'.$cartId.'"');
}
}
}
}
}
if (isset($category) == "DeleteItem") {
if (isset($postdata->cart_item_delete)) {
$cartId = $postdata->cart_item_delete;
$delete_item_cart = mysqli_query($connection, 'delete from cart_table where id = "'.$cartId.'"');
}
}
// include 'layout/footer.php';
?>