-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_quantity.php
143 lines (136 loc) · 5.49 KB
/
update_quantity.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
include './functions/common_files.php';
session_start();
if(!isset($_SESSION['user_id'])){
get_cart_details();
}
$user_id = $_SESSION['user_id'];
if(isset($_POST['update_product_quantity'])){
include 'connect.php';
if(!empty($_POST['quantity'])){
$product_quantity = $_POST['quantity'];
$item_id = $_POST['product_id'];
$update_quantity = "UPDATE `carts` SET `quantity`=? WHERE `product_id`=? AND `user_id`=?";
$result = $con->prepare($update_quantity);
$result->bind_param('iii',$product_quantity,$item_id,$user_id);
if($result->execute()){
echo "<script>window.open('cart_table.php','_self');</script>";
}
else{
echo "<script>window.open('cart_table.php','_self');</script>";
}
$result->close();
}
else{
echo "<script>window.open('cart_table.php','_self');</script>";
}
$con->close();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?php get_current_url(); ?></title>
<link rel="icon" type="image/png" href="./all_images/logo.png" />
<link rel="stylesheet" href="./css/cart_table.css" />
<link rel="stylesheet" href="./css/user_sidebar.css" />
<link rel="stylesheet" href="./css/header.css"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.6.0/css/all.min.css"/>
</head>
<body>
<?php
if(isset($_GET['update_product_id'])){
include 'connect.php';
if(!empty($_GET['update_product_id'])){
$update_product_id = $_GET['update_product_id'];
$select_product = "SELECT `product_id`,`user_id` FROM `carts` WHERE `product_id`=? AND `user_id`=?";
$result_product = $con->prepare($select_product);
$result_product->bind_param('ii',$update_product_id,$user_id);
if($result_product->execute()){
$result_product->store_result();
if($result_product->num_rows > 0){
?>
<?php
get_header();
get_user_profile();
?>
<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="post">
<table>
<thead>
<tr>
<th>Product Name</th>
<th>Product Image</th>
<th>Quantity</th>
<th>Product Price</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
if(isset($_GET['update_product_id'])){
include 'connect.php';
$product_id = $_GET['update_product_id'];
$select_cart_query = "SELECT * FROM `carts` WHERE `user_id`=? AND `product_id`=?";
$result = $con->prepare($select_cart_query);
$result->bind_param('ii',$user_id,$product_id);
$result->execute();
$cart_items = $result->get_result();
if($cart_items->num_rows > 0){
$row = $cart_items->fetch_assoc();
$select_query = "SELECT product_id,product_name,product_image1,product_price FROM `products` WHERE `product_id`=?";
$answer = $con->prepare($select_query);
$answer->bind_param('i',$product_id);
$answer->execute();
$product_items = $answer->get_result();
$rows = $product_items->fetch_assoc();
$product_id = $rows['product_id'];
$product_name = $rows['product_name'];
$product_image1 = $rows['product_image1'];
$product_price = $rows['product_price'];
?>
<tr>
<td><?php echo $product_name; ?></td>
<td class="product-image"><img src="./product_images/<?php echo $product_image1; ?>" alt="<?php echo $product_name; ?>"></td>
<td><input type="hidden" name="product_id" value="<?php echo $product_id; ?>"><input type="number" min="1" max="10" name="quantity" class="change-quantity" required></td>
<td>Rs.<?php echo number_format($rows['product_price'],2,'.',','); ?>/-</td>
<td><button type="submit" class="update-quantity-button" name="update_product_quantity">Update</button></td>
</tr>
<?php
$answer->close();
}
$cart_items->close();
$result->close();
}
?>
</tbody>
</table>
</form>
<div class="cart-summary">
<div class="buttons">
<button><a href="home.php">Continue Shopping</a></button>
<button><a href="cart_table.php">Back</a></button>
</div>
</div>
<?php
}
else{
echo "<script>window.open('cart_table.php','_self');</script>";
}
}
else{
echo "<script>window.open('cart_table.php','_self');</script>";
}
$result_product->close();
}
else{
echo "<script>window.open('cart_table.php','_self');</script>";
}
$con->close();
}
?>
<script src="./js/sidebar.js"></script>
<script src="./js/user-sidebar2.js"></script>
</body>
</html>