forked from Astha1404/charvi
-
Notifications
You must be signed in to change notification settings - Fork 1
/
product.php
243 lines (236 loc) · 9.65 KB
/
product.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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<?php require_once 'header.php' ?>
</head>
<body>
<?php
if(!isset($_SESSION))
{
session_start();
}
require_once 'dbconnection.php';
if(isset($_POST['submitFeedback']))
{
if(!isset($_SESSION['email']))
{
echo "<script>window.location.href='login.php';</script>";
}
else
{
$feedback = $_POST['feedback'];
$rating = $_POST['rating'];
$id = $_POST['submitFeedback'];
$sql = "INSERT INTO `feedback`(`PRODUCT_ID`, `USER_ID`, `FEEDBACK`, `RATING`) VALUES ({$id},{$_SESSION['userId']},'{$feedback}','{$rating}')";
$result = mysqli_query($con,$sql);
if($result)
{
echo "<script>window.location.href='product.php?id={$id}';</script>";
}
}
}
if(isset($_POST['addToCart']))
{
$pid = $_POST['addToCart'];
$userId = $_SESSION['userId'];
$qty = $_POST['qty'];
$_GET['id'] = $pid;
$sql = "SELECT * FROM `cart` WHERE product_id='{$pid}' AND user_id='{$userId}'";
$result = mysqli_query($con,$sql);
unset($_POST);
if(mysqli_num_rows($result)==0)
{
if(!isset($_SESSION['email']))
{
echo "<script>window.location.href='login.php';</script>";
}
$sql1 = "INSERT INTO `cart`(`user_id`, `product_id`, `quantity`) VALUES ('{$userId}','{$pid}','{$qty}')";
$result = mysqli_query($con,$sql1);
if($result)
{
$success = "Product is Added To Your Cart Successfully";
echo "<script>window.location.href='product.php?id={$pid} & success={$success}';</script>";
}
else
{
$error = "Can't Add This Product To Your Cart Right Now";
echo "<script>window.location.href='product.php?id={$pid} & error={$error}';</script>";
}
}
else
{
$error = "The Product is Already in Your Cart";
echo "<script>window.location.href='product.php?id={$pid} & error={$error}';</script>";
}
}
require_once 'navbar.php';
?>
<div class="container-fluid p-0 mb-4 mx-0 pb-4 row">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" class="row p-0 m-0">
<?php
if(!isset($_GET['id']))
{
echo "<h1 class='text-center text-dark my-5 py-5'>404 - Page NOT Found</h1>";
die();
}
if(isset($_GET['like']) && isset($_SESSION['email']))
{
$sql = "SELECT * FROM wishlist WHERE user_id={$_SESSION['userId']} AND product_id={$_GET['id']}";
$result = mysqli_query($con,$sql);
if(mysqli_num_rows($result)==0)
{
$sql = "INSERT INTO `wishlist`(`USER_ID`, `PRODUCT_ID`) VALUES ('{$_SESSION['userId']}','{$_GET['id']}')";
$result = mysqli_query($con,$sql);
echo "<script>window.location.href='product.php?id={$_GET['id']}';</script>";
}
else
{
$sql = "DELETE FROM `wishlist` WHERE user_id={$_SESSION['userId']} AND product_id={$_GET['id']}";
$result = mysqli_query($con,$sql);
echo "<script>window.location.href='product.php?id={$_GET['id']}';</script>";
}
}
if(isset($_GET['like']) && !isset($_SESSION['email']))
{
echo "<script>window.location.href='login.php';</script>";
}
$sql = "SELECT * FROM product WHERE product_id = {$_GET['id']}";
$result = mysqli_query($con,$sql);
if(mysqli_num_rows($result)!=1)
{
echo "<h1 class='text-center text-dark my-5 py-5'>404 - Page NOT Found</h1>";
die();
}
else
{
$row = mysqli_fetch_assoc($result);
$img = $row['IMAGE'];
$name = $row['PRODUCT_NAME'];
$price = $row['PRICE'];
$qty = $row["QUANTITY"];
$desc = $row["DESCRIPTION"];
$id = $row['PRODUCT_ID'];
$category = $row['CATEGORY_ID'];
$company = $row['COMPANY_ID'];
$sql = "SELECT category_name FROM category WHERE category_id = {$category}";
$result = mysqli_query($con,$sql);
$row = mysqli_fetch_assoc($result);
$category = $row['category_name'];
$sql = "SELECT company_name FROM company WHERE company_id = {$company}";
$result = mysqli_query($con,$sql);
$row = mysqli_fetch_assoc($result);
$company = $row['company_name'];
if(isset($_SESSION['email']))
{
$sql = "SELECT * FROM wishlist WHERE user_id = {$_SESSION['userId']} AND product_id={$id}";
$result = mysqli_query($con,$sql);
$like = mysqli_num_rows($result)==1?true:false;
}
else
{
$like = false;
}
echo "<div class='col-md-6 col-sm-12 col-12 mx-auto overflow-hidden m-0 p-0'>
<div class='position-relative'>
<img src='{$product_images}{$img}' class='img-fluid w-100'>";
if($like)
{
echo "<a href='{$_SERVER['PHP_SELF']}?id={$id} & like=1' class='position-absolute end-0 top-0 px-4 py-1 bg-light'><span><i class='bi bi-heart-fill text-danger fs-2'></i></span></a>";
}
else
{
echo "<a href='{$_SERVER['PHP_SELF']}?id={$id} & like=0' class='position-absolute end-0 top-0 px-4 py-1 bg-light'><span><i class='bi bi-heart text-danger fs-2'></i></span></a>";
}
echo" </div>
<div class='row'>
<button type='submit' name='addToCart' value='{$id}' class='btn btn-primary col-12 p-3 fs-5'>Add To Cart <i class='bi bi-basket'></i></button>
</div>
</div>
<div class='col-md-6 col-sm-12 col-12 mx-auto overflow-hidden m-0 p-0 row my-sm-2 my-md-0'>
<div class='container-fluid m-0 p-0 col-6 col-md-12'>
<h2 class='text-light bg-dark p-4'>{$name}</h2>
<h3 class='text-dark m-4'>Price : {$price} Rs / Pkt</h3>
<h3 class='text-dark m-4'>Quantity : {$qty} gm</h3>
<h4 class='text-dark m-4'>Category : {$category}</h4>
<h4 class='text-dark m-4'>Brand : {$company}</h4>
<div class='d-flex align-items-center'>
<h4 class='d-inline text-dark mx-4'>Product Quantity : </h4><input type='number' value='1' name='qty' class='form-control w-25 d-inline' required/>
</div>
<div class='ratings fs-2 m-4'>
<h4 class='text-dark'>Ratings : </h4>";
$sql2 = "SELECT AVG(rating) AS avg FROM feedback WHERE product_id={$_GET['id']}";
$result2 = mysqli_query($con,$sql2);
$row2 = mysqli_fetch_array($result2);
$stars = $row2['avg'];
$i=1;
if($stars>0)
{
$stars = ceil($stars);
}
else
{
$stars = 0;
}
$n = $stars;
$flag=1;
while($i<=5)
{
if($i<=$n)
{
echo '<i class="bi bi-star-fill text-warning"></i> ';
}
else
{
if($flag==1)
{
$flag=0;
if(($stars*2)%2==1)
{
echo '<i class="bi bi-star-half text-warning"></i>';
}
else
{
echo '<i class="bi bi-star"></i>';
}
}
else
{
echo '<i class="bi bi-star"></i>';
}
}
$i = $i+1;
}
echo "</div>
</div>
<div class='container-fluid mx-auto m-0 p-0 col-6 col-md-12'>
<h2 class='text-center bg-secondary text-light py-4 p-0'>Description</h2>
<p class='m-4 text-center fs-5'>{$desc}</p>
</div>
</div>";
?>
</form>
<?php } ?>
</div>
<?php
require_once 'feedback.php';
require_once 'other-menulist.php';
require_once 'userDashboard.php';
if(isset($_GET['success']))
{
$success=$_GET['success'];
require_once 'success.php';
}
if(isset($_GET['error']))
{
$error=$_GET['error'];
require_once 'error.php';
}
require_once 'footer.php';
?>
</body>
<?php require_once 'scripts.php'; ?>
</html>