-
Notifications
You must be signed in to change notification settings - Fork 0
/
search_page.php
109 lines (82 loc) · 3.51 KB
/
search_page.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
<?php
include 'config.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!';
}
};
?>
<!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>search page</title>
<!-- font awesome cdn link -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<!-- custom css file link -->
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="style.css">
<script type="text/javascript" src="script1.js"></script>
<script type="text/javascript" src="script1.js"></script>
<link rel="stylesheet" type="text/css" href="style1.css">
</head>
<body>
<?php include 'header.php'; ?>
<h1 style="text-align:center;">Search page</h1>
<section class="search-form">
<form action="" method="post">
<input id="search" type="text" name="search" placeholder="search products..." class="box">
<input type="submit" name="submit" value="search" class="btn">
</form>
</section>
<section class="products" style="padding-top: 0;" id="display" >
<div class="box-container">
<?php
if(isset($_POST['submit'])){
$search_item = $_POST['search'];
$select_products = mysqli_query($conn, "SELECT * FROM `products` WHERE name LIKE '%{$search_item}%' OR `genre` LIKE '%{$search_item}%'") or die('query failed');
if(mysqli_num_rows($select_products) > 0){
while($fetch_product = mysqli_fetch_assoc($select_products)){
?>
<form action="" method="post" class="box" id="display">
<img src="uploaded_img/<?php echo $fetch_product['image']; ?>" alt="" class="image">
<div class="name"><?php echo $fetch_product['name']; ?></div>
<div class="price">$<?php echo $fetch_product['price']; ?>/-</div>
<input type="number" class="qty" name="product_quantity" min="1" value="1">
<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']; ?>">
<input type="submit" class="btn" value="add to cart" name="add_to_cart">
</form>
<?php
}
}else{
echo '<p class="empty">no result found!</p>';
}
}else{
echo '<p class="empty">search something!</p>';
}
?>
</div>
</section>
<?php include 'footer.php'; ?>
<!-- custom js file link -->
<script src="script.js"></script>
</body>
</html>