-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
174 lines (138 loc) · 6.7 KB
/
index.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
<?php
$title = 'Shop';
include './php/config.php';
session_start();
if(isset($_SESSION['admin_id'])){
$user_id = $_SESSION['admin_id'];
include './templates/admin_header.php';
} elseif(isset($_SESSION['user_id'])){
$user_id = $_SESSION['user_id'];
include './templates/user_header.php';
} else
include './templates/header.php';
if(isset($_POST['add_to_cart'])){
if (!isset($user_id)){
echo '<script>alert("Please login to add books to cart!");
window.location.href="login.php";</script>';
}else {
$book_id = $_POST['book_id'];
$book_title = $_POST['book_title'];
$book_price = $_POST['book_price'];
$book_image = $_POST['book_image'];
$book_quantity = $_POST['book_quantity'];
$sql = "SELECT * FROM cart WHERE title = '$book_id' AND user_id = '$user_id'";
$result = mysqli_query($con, $sql);
if(mysqli_num_rows($result) > 0){
echo '<script>alert("Book already added to cart!")</script>';
} else {
$sql = "INSERT INTO cart (user_id, title, price, quantity, image) VALUES ('$user_id', '$book_title', '$book_price', '$book_quantity', '$book_image')";
$result = mysqli_query($con, $sql);
if($result){
echo '<script>alert("Book Added to Cart Successfully!");
window.location.href="shop.php";</script>';
} else {
echo '<script>alert("Book not added to cart!")</script>';
}
}
}
}
?>
<link rel="stylesheet" href="./css/index.css">
<link rel="stylesheet" href="./css/shop.css">
<div id="slider">
<figure><a href="shop.php">
<img src="./src/banner.jpg">
<img src="./src/banner2.jpg">
<img src="./src/banner3.jpg">
<img src="./src/banner4.jpg">
</a></figure>
</div>
<p class="maintitle">Welcome to Eden BookStore</p>
<div class="row">
<div class="col-1">
<img src="./src/qickdelivery.png">
<p class="banner1">Quick Delivery</p>
</div>
<div class="col-1">
<img src="./src/securepayment.png">
<p class="banner1">Secure Payment</p>
</div>
<div class="col-1">
<img src="./src/bestquality.png">
<p class="banner1">Best Quality</p>
</div>
</div>
<!--featured categories-->
<div class="main-container" style="display:block;align-items: flex-start;">
<h1 style="text-align:center;">Featured Books</h1>
<div class="book-container" style="margin:30px 0;">
<?php
$select_books = mysqli_query($con, "SELECT * FROM books") or die('query failed');
$select_category= mysqli_query($con, "SELECT name FROM categories INNER JOIN books ON categories.id = books.category_id") or die('query failed');
if(mysqli_num_rows($select_books) > 0){
while(($fetch_books = mysqli_fetch_assoc($select_books)) AND ($fetch_category = mysqli_fetch_assoc($select_category))){
?>
<div class="book-card">
<form action="" method="post" class="cart-box">
<img class="image" src="./src/uploads/<?php echo $fetch_books['image'] ?>" alt="">
<div class="info">
<h3><?php echo $fetch_books['title'] ?></h3>
<p><?php echo $fetch_category['name'] ?></p>
<div class="price-qty">
<span>$<?php echo $fetch_books['price'] ?></span>
<input type="number" name="book_quantity" value="1" min="1" id="book_quantity" class="qty">
</div>
<input type="hidden" name="book_id" value="<?php echo
$fetch_books['id'] ?>">
<input type="hidden" name="book_title" value="<?php echo
$fetch_books['title'] ?>">
<input type="hidden" name="book_price" value="<?php echo
$fetch_books['price'] ?>">
<input type="hidden" name="book_image" value="<?php echo
$fetch_books['image'] ?>">
<?php
echo '<div class="btn-1">
<button type="submit" value="Add to cart" name="add_to_cart" class="btn"><img src="./src/cart.svg" alt="" style="width:25px; margin-right:10px;"> Add to cart</button>
</div>';
?>
</div>
</form>
</div>
<?php
}
} else {
echo '<p class="empty">No books added yet!</p>';
}
?>
</div>
<h1 style="text-align:center;">Customer Reviews</h1>
<br>
<div id="slideshow">
<div class="slider">
<div class="slide">
<h2 class="feedbacktopic">"Amazing service."</h2>
<img class=feedbackss src="src/image1.png";>
<p class="description">One of the best market palce for books. I really wonder about their services and book collection </p>
</div>
<div class="slide">
<h2 class="feedbacktopic">"Best market palce. Highly Recommended"</h2>
<img class=feedbackss src="src/image2.png";>
<p class="description">This website helps me to find the best acedemic books that are related for my studies. Don't be hesitate to purchase your books from this site. </p>
</div>
<div class="slide">
<h2 class="feedbacktopic">"Best collection"</h2>
<img class=feedbackss src="./src/image3.png";>
<p class="description">This has vast collection of books and that is very helpful form my studies. I really like this website </p>
</div>
<div class="slide">
<h2 class="feedbacktopic">"Execellent customer service"</h2>
<img class=feedbackss src="src/image4.png";>
<p class="description">Friendly and fast communication. They help me solve my problem within few minutes. Really glad about that. </p>
</div>
</div>
</div>
</body>
<?php
include './templates/newsletter.php';
include './templates/footer.php';
?>