-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.php
149 lines (120 loc) · 5.84 KB
/
search.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
<?php
include "inc/db.php";
session_start();
$user_id = $_SESSION['user_id'];
if (!isset($user_id)) {
header('location:login.php');
}
if (isset($_POST['add_to_cart'])) {
$product_name = $_POST['product_name'];
$product_price = $_POST['product_price'];
$product_image = $_POST['product_image'];
$product_quantity = $_POST['product_quantity'];
$check_cart_numbers = mysqli_query($conn, "SELECT * FROM `cart` WHERE name = '$product_name' AND user_id = '$user_id'") or die('query failed');
if (mysqli_num_rows($check_cart_numbers) > 0) {
$message[] = 'Already added to cart!';
} else {
mysqli_query($conn, "INSERT INTO `cart`(user_id, name, price, quantity, image) VALUES('$user_id', '$product_name', '$product_price', '$product_quantity', '$product_image')") or die('query failed');
$message[] = 'Product added to cart!';
}
}
;
?>
<?php
include "inc/header.php";
?>
<!-- Header Start -->
<div class="container-fluid bg-primary py-5 mb-5 page-header">
<div class="container py-5">
<div class="row justify-content-center">
<div class="col-lg-10 text-center">
<h1 class="display-3 text-white animated slideInDown">Search</h1>
<nav aria-label="breadcrumb">
<ol class="breadcrumb justify-content-center">
<li class="breadcrumb-item"><a class="text-white" href="home.php">Home</a></li>
<li class="breadcrumb-item"><a class="text-white" href="#">Search</a></li>
</ol>
</nav>
</div>
</div>
</div>
</div>
<!-- Header End -->
<!-- Login Start -->
<div class="container-xxl py-2 mt-4">
<div class="container">
<div class="row g-4 wow fadeInUp" data-wow-delay="0.5s ">
<form method="post" class="w-100 d-flex justify-content-between">
<input type="text" name="search" placeholder="Search Books..." class="form-control p-2">
<input type="submit" value="Submit" class="btn text-light" name="submit">
</form>
<div class="py-2">
<?php
if (isset($message)) {
foreach ($message as $message) {
echo '<div class="message alert alert-success d-flex justify-content-between">
<span>' . $message . '</span>
<i class="fas fa-times" onclick="this.parentElement.remove();"></i>
</div>
';
}
}
?>
</div>
<div class="col-lg-3 col-md-6 col-sm-12">
<?php
if (isset($_POST['submit'])) {
$search_item = $_POST['search'];
$select_products = mysqli_query($conn, "SELECT * FROM `products` WHERE name LIKE '%{$search_item}%'") or die('query failed');
if (mysqli_num_rows($select_products) > 0) {
while ($fetch_product = mysqli_fetch_assoc($select_products)) {
?>
<div class="card shadow">
<a href="#">
<img src="uploaded_img/<?php echo $fetch_product['image']; ?>" class="img-fluid" alt="..."
width="100%">
</a>
<div class="card-body p-4">
<h5 class="card-title"><a href="" class="text-dark">
<?php echo $fetch_product['name']; ?>
</a></h5>
<p>
<?php echo $fetch_product['author']; ?>
</p>
<p>
₹
<?php echo $fetch_product['price']; ?>/-
</p>
<form action="" method="POST">
<input type="number" class="p-1" name="product_quantity" min="1" value="1"
style="width:100px;">
<input type="hidden" name="product_name" value="<?php echo $fetch_product['name']; ?>">
<input type="hidden" name="product_price" value="₹<?php echo $fetch_product['price']; ?>/-">
<input type="hidden" name="product_image" value="<?php echo $fetch_product['image']; ?>">
<?php if (!isset($_SESSION["user_id"]) == true): ?>
<a href="login.php" class="btn text-light">Add To Cart</a>
<?php else: ?>
<input type="submit" class="btn text-light" value="Add To Cart" name="add_to_cart">
<?php endif; ?>
</form>
</div>
</div>
<?php
}
} else {
echo '<center>
<img src="images/not_found.jpg" alt="not_found" class"img-fluid" style="width:500px;">
</center>';
}
} else {
echo '<p class="empty">Search Something!</p>';
}
?>
</div>
</div>
</div>
</div>
<!-- Login End -->
<?php
include "inc/footer2.php";
?>