forked from perfectfury/study_project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearch_page.php
More file actions
110 lines (102 loc) · 4.13 KB
/
search_page.php
File metadata and controls
110 lines (102 loc) · 4.13 KB
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
<?php
include 'config.php';
include 'get_function.php';
session_start();
$user_id = $_SESSION['user_id'];
if (!isset($user_id)) {
header('location:login.php');
};
if (isset($_POST['add_to_cart'])) {
$book_id = $_POST['book_id'];
$book_amount = $_POST['book_amount'];
$book_quantity = 1;
if ($book_quantity > $book_amount) {
$message[] = 'Невозможно забронировать такое количество книг!';
}
else {
mysqli_query($conn,
"INSERT INTO `cart`(USER_ID, BOOK_ID, BOOK_AMOUNT) VALUES('$user_id', '$book_id', '$book_quantity')") or die('query failed');
$message[] = 'Книга добавлена в корзину!';
}
};
?>
<!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>страница поиска</title>
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
<link rel="stylesheet" href="css/style.css">
<script src="js/search.js"></script>
</head>
<body>
<?php include 'header.php'; ?>
<div class="heading">
<h3>страница поиска</h3>
<p><a href="home.php">главная</a> / поиск </p>
</div>
<section class="search-form">
<form action="" method="post">
<input type="text" name="search" id="dName" placeholder="начать поиск..."
class="box" style="width: 100%" >
<script>
ac.attach({
target: document.getElementById("dName"),
data: "2b-search.php"
});
</script>
<input type="submit" name="submit" value="поиск" class="btn">
</form>
</section>
<section class="books" style="padding-top: 0;">
<div class="box-container">
<?php
if (isset($_POST['submit'])) {
$search_item = $_POST['search'];
$select_books = mysqli_query($conn,
"SELECT * FROM `books` WHERE BOOK_NAME LIKE '%{$search_item}%'") or die('query failed');
if (mysqli_num_rows($select_books) > 0) {
while ($fetch_books = mysqli_fetch_assoc($select_books)) {
$author_by_id = getColFromTable($conn, 'authors', 'AUTH_ID', $fetch_books['AUTH_ID']);
$amount = $fetch_books['BOOK_AMOUNT'];
?>
<form action="" method="post" class="box">
<a href="details.php?id=<?= $fetch_books['BOOK_ID'] ?>">
<img class="image"
src="uploaded_img/<?= $fetch_books['BOOK_IMG'] ?>"
width="100%" alt=""></a>
<div class="desc">
<div class="name"><?= $fetch_books['BOOK_NAME'] ?></div>
<div class="amount"><?= $amount ?> шт.</div>
<div class="name"><?= $author_by_id['AUTH_NAME'] ?></div>
<input type="hidden" name="book_id"
value="<?= $fetch_books['BOOK_ID'] ?>">
<input type="hidden" name="book_name"
value="<?= $fetch_books['BOOK_NAME'] ?>">
<input type="hidden" name="book_amount"
value="<?= $fetch_books['BOOK_AMOUNT'] ?>">
<input type="submit" value="В корзину"
name="add_to_cart"
class="btn <?= ($amount != 0) ? '' : 'disabled' ?>">
</div>
</form>
<?php
}
}
else {
echo '<p class="empty">Ничего не нашлось!</p>';
}
}
else {
echo '<p class="empty">Поищите что-нибудь!</p>';
}
?>
</div>
</section>
<?php include 'footer.php'; ?>
<script src="js/script.js"></script>
</body>
</html>