-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcart.php
More file actions
192 lines (145 loc) · 5.18 KB
/
cart.php
File metadata and controls
192 lines (145 loc) · 5.18 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
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<?php
/* $con = mysqli_connect("localhost","root","") or die("Unable to connect");
mysqli_select_db($con,"bharatsports");*/
include('include/connection.php');
session_start();
error_reporting(0);
?>
<!DOCTYPE html>
<html>
<head>
<title>Cart</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Shopping Cart</title>
<!-- Font Awesome - -->
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.2/css/all.css">
<link rel="stylesheet" type="text/css" href="fontawesome/css/all.css">
<link rel="stylesheet" href="style.css" media="screen" title="no title" charset="utf-8">
<link rel="icon" href="logo/webs.png" type="image/icon type">
<script src="https://code.jquery.com/jquery-2.2.4.js" charset="utf-8"></script>
<meta name="robots" content="noindex,follow" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<?php
$userid = $_SESSION['userid'];
/*$query = "SELECT * FROM ((carts INNER JOIN likes ON carts.userid = likes.userid)
INNER JOIN product ON carts.product_id = product.id) ";*/
$query = "SELECT * FROM carts JOIN product ON carts.product_id = product.id WHERE user_id ='$userid' ";
$result = mysqli_query($con, $query);
if(mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_array($result))
{
?>
<div class="shopping-cart">
<!-- Title -->
<div class="title">
Shopping Bag
</div>
<form method="POST">
<!-- Product #1 -->
<div class="item">
<div class="buttons">
<input type="submit" name="remove" class="delete-btn" value="">
<!-- <button type="submit" name="remove"> <span ></span></button> -->
</div>
<div class="image">
<img src="<?php echo $row["img"]; ?>" alt="" />
</div>
<div class="description">
<span><?php echo $row["name"]; ?></span>
</div>
<div class="quantity">
<button class="plus-btn" type="button" name="button">
<img src="plus.svg" alt="" />
</button>
<input type="text" name="order_qty" value="<?php echo $row["qty"]; ?>">
<button class="minus-btn" type="button" name="button">
<img src="minus.svg" alt="" />
</button>
</div>
<div class="total-price" id="total"><i class="fa fa-rupee-sign" aria-hidden="true"></i>
<input class="input-price" type="text" name="price" value="<?php echo $row["price"]; ?>">
</div>
<input type="hidden" name="productid" value="<?php echo $row["id"]; ?>">
<input type="submit" class="order" name="order" value="Check out">
</form>
</div>
</div>
<?php
}
}
if(mysqli_num_rows($result) === 0)
{
echo '<h1 class="noitem">"No Item in the Cart"</h1>';
}
?>
<script type="text/javascript">
$('.minus-btn').on('click', function(e) {
e.preventDefault();
var $this = $(this);
var $input = $this.closest('div').find('input');
var value = parseInt($input.val());
if (value > 1) {
value = value - 1;
} else {
value = 0;
}
$input.val(value);
});
$('.plus-btn').on('click', function(e) {
e.preventDefault();
var $this = $(this);
var $input = $this.closest('div').find('input');
var value = parseInt($input.val());
if (value < 10000) {
value = value + 1;
} else {
value =100;
}
$input.val(value);
});
</script>
</body>
</html>
<?php
if(isset ($_POST['order']))
{
$user_id = $_SESSION['userid'];
$orderqty = $_POST['order_qty'];
$price = $_POST['price'];
$productid = $_POST['productid'];
$status = "Order Placed";
$query ="INSERT INTO `order` (productid,order_qty,total_price,user_id,status) VALUES ('$productid','$orderqty','$price','$user_id','$status')";
$query_run = mysqli_query($con,$query);
if($query_run)
{
//echo "Saved";
{
echo '<script> alert("Ordered Placed Successfully") </script>';
}
}
else
{
echo '<script> alert("Errro ") </script>';
}
}
if(isset ($_POST['remove']))
{
$user_id = $_SESSION['userid'];
$productid = $_POST['productid'];
$query ="DELETE FROM `carts` WHERE userid = '$user_id' AND product_id = '$productid'";
$query_run = mysqli_query($con,$query);
if($query_run)
{
//alert msg of remove product "-(_-"
echo '<script> alert("Product Remove from Cart") </script>';
}
else
{
echo '<script> alert("Some Errro ") </script>';
}
}
?>