-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.php
206 lines (185 loc) · 6.08 KB
/
action.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
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<?php
session_start();
include "db.php";
if(isset($_POST["category"])){
$category_query="SELECT * FROM categories";
$run_query=mysqli_query($con,$category_query);
echo"<div class ='nav nav-pills nav-stacked'>
<li class='active'><a href ='#'><h3>Categories</h3></a></li>
";
if(mysqli_num_rows($run_query)>0)
{
while($row = mysqli_fetch_array($run_query)){
$cid=$row["cat_id"];
$cat_name=$row["cat_title"];
echo"
<li><a href ='#' class='category' cid='$cid'>$cat_name</a></li>
";
}
echo "</div>";
}
}
if(isset($_POST["brand"])){
$brand_query="SELECT * FROM brands";
$run_query=mysqli_query($con,$brand_query);
echo"<div class ='nav nav-pills nav-stacked'>
<li class='active'><a href ='#'><h3>Brands</h3></a></li>
";
if(mysqli_num_rows($run_query)>0)
{
while($row = mysqli_fetch_array($run_query)){
$bid=$row["brand_id"];
$brand_name=$row["brand_title"];
echo"
<li><a href ='#' class='selectBrand' bid='$bid'>$brand_name</a></li>
";
}
echo "</div>";
}
}
if(isset($_POST["getProduct"])){
$product_query="SELECT * FROM products ORDER BY RAND() LIMIT 0,9";
$run_query=mysqli_query($con,$product_query);
if(mysqli_num_rows($run_query)>0)
{
while($row = mysqli_fetch_array($run_query)){
$pro_id=$row['product_id'];
$pro_cat=$row['produt_cat'];
$pro_brand=$row['product_brand'];
$pro_title=$row['product_title'];
$pro_price=$row['product_price'];
$pro_image=$row['product_image'];
echo"
<script src=\"review.js\"></script>
<div class='col-md-4' id=\"prod\">
<div class='panel panel-info'>
<div class ='panel-heading'>$pro_title </div>
<div class='panel-body'>
<img src='images/$pro_image' style='width:160px ; height:250px;'/>
</div>
<div class='panel-heading'>$pro_price.00
<button pid='$pro_id' style='float:right;' class='btn btn-danger'> Add to cart</button>
</div>
</div>
</div>
";
}
}
}
if(isset($_POST["get_selected_Category"]) ||isset($_POST["selectBrand"])){
if(isset($_POST["get_selected_Category"]))
{
$id=$_POST["cat_id"];
$sql="SELECT * from products WHERE produt_cat='$id'";
}
else if(isset($_POST["selectBrand"]))
{
$id=$_POST["brand_id"];
$sql="SELECT * from products WHERE product_brand='$id'";
}
$run_query=mysqli_query($con,$sql);
while($row = mysqli_fetch_array($run_query)){
$pro_id=$row['product_id'];
$pro_cat=$row['produt_cat'];
$pro_brand=$row['product_brand'];
$pro_title=$row['product_title'];
$pro_price=$row['product_price'];
$pro_image=$row['product_image'];
echo"<script src=\"review.js\"></script>
<div class='col-md-4' id=\"prod\">
<div class='panel panel-info'>
<div class ='panel-heading' id=\"pro_title\">$pro_title </div>
<div class='panel-body'>
<img src='images/$pro_image' style='width:160px ; height:250px;'/>
</div>
<div class='panel-heading'>$pro_price.00
<button pid='$pro_id' style='float:right;' class='btn btn-danger'> Add to cart</button>
</div>
</div>
</div>
";
}
}
if(isset($_POST["search"]))
{
$keyword=$_POST["keyword"];
$sql="SELECT * from products WHERE product_keywords LIKE '%$keyword%'";
$run_query=mysqli_query($con,$sql);
while($row = mysqli_fetch_array($run_query)){
$pro_id=$row['product_id'];
$pro_cat=$row['produt_cat'];
$pro_brand=$row['product_brand'];
$pro_title=$row['product_title'];
$pro_price=$row['product_price'];
$pro_image=$row['product_image'];
echo"<script src=\"review.js\"></script>
<div class='col-md-4' id=\"prod\">
<div class='panel panel-info'>
<div class ='panel-heading' id=\"pro_title\">$pro_title </div>
<div class='panel-body'>
<img src='images/$pro_image' style='width:160px ; height:250px;'/>
</div>
<div class='panel-heading'>$pro_price.00
<button pid='$pro_id' style='float:right;' class='btn btn-danger'> Add to cart</button>
<button pid='$pro_id' style='float:right;' class='btn btn-danger' onclick=\"showreview()\"> reviews</button>
</div>
</div>
</div>
";
}
}
if(isset($_POST["addToProduct"])){
$p_id=$_POST["proId"];
$user_id=$_SESSION["uid"];
$sql="SELECT * FROM cart WHERE p_id='$p_id' AND user_id='$user_id'";
$run_query=mysqli_query($con,$sql);
$count=mysqli_num_rows($run_query);
if($count>0)
{
echo "product is already added to cart.... ";
}else{
$sql="SELECT * FROM products WHERE product_id='$p_id'";
$run_query=mysqli_query($con,$sql);
$row=mysqli_fetch_array($run_query);
$id=$row["product_id"];
$pro_name=$row["product_title"];
$pro_image=$row["product_image"];
$pro_price=$row["product_price"];
$sql="INSERT INTO `cart` (`id`, `p_id`, `ip_add`, `user_id`, `product_title`, `product_image`, `qty`, `price`, `total_amout`) VALUES (NULL, '$p_id', '0', '$user_id', '$pro_name', '$pro_image', '1', '$pro_price', '$pro_price');";
if(mysqli_query($con,$sql)){
echo "
<div class='alert alert-success'>
<a href='#' class='close' data-dismiss='alert' aria-label='close'> ×</a>
<b>Product is added...</b>
</div>
";
}
}
}
if(isset($_POST["get_cart_product"])){
$uid=$_SESSION["uid"];
$sql="SELECT * FROM cart WHERE user_id='$uid'";
$run_query=mysqli_query($con,$sql);
$count=mysqli_num_rows($run_query);
if($count>0)
{
$no=1;
while($row=mysqli_fetch_array($run_query)){
$id=$row["id"];
$pro_id=$row["p_id"];
$pro_name=$row["product_title"];
$pro_image=$row["product_image"];
$pro_price=$row["price"];
echo"
<div class='row'>
<div class='col-md-3'>$no</div>
<div class='col-md-3'><img src='images/$pro_image' width='60px' height='50px'></div>
<div class='col-md-3'>$pro_name</div>
<div class='col-md-3'>Rs.$pro_price.00</div>
</div>
";
$no=$no+1;
}
}
}
?>