-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbook_management.php
199 lines (178 loc) · 5.58 KB
/
book_management.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
<?php
$title = "Book Management";
include("lib/header.php");
?>
<!-- Form for adding a book -->
<h2>Add Book</h2>
<form action="add_book.php" method="post" id="addBookForm">
<label for="title">Title:</label>
<input type="text" id="title" name="title" required>
<br>
<label for="author">Author:</label>
<input type="text" id="author" name="author" required>
<br>
<label for="genre">Genre:</label>
<input type="text" id="genre" name="genre" required>
<br>
<label for="transactionID">TransactionID:</label>
<input type="text" id="transactionID" name="transactionID" required>
<br>
<label for="isbn">ISBN:</label>
<input type="text" id="isbn" name="isbn" required>
<span id="isbnError" class="error"></span> <!-- Error message container -->
<br>
<button type="submit">Add Book</button>
</form>
<!-- Form for updating a book -->
<h2>Update Book</h2>
<form action="update_book.php" method="post" id="updateBookForm">
<label for="isbnToUpdate">ISBN to Update:</label>
<input type="text" id="isbnToUpdate" name="isbnToUpdate" required>
<span id="isbnToUpdateError" class="error"></span> <!-- Error message container -->
<br>
<!-- Input fields for new book details -->
<label for="newTitle">New Title:</label>
<input type="text" id="newTitle" name="newTitle" required>
<br>
<label for="newAuthor">New Author:</label>
<input type="text" id="newAuthor" name="newAuthor" required>
<br>
<label for="newGenre">New Genre:</label>
<input type="text" id="newGenre" name="newGenre" required>
<br>
<button type="submit">Update Book</button>
</form>
<!-- Form for deleting a book -->
<h2>Delete Book</h2>
<form action="delete_book.php" method="post" id="deleteBookForm">
<label for="isbnToDelete">ISBN to Delete:</label>
<input type="text" id="isbnToDelete" name="isbnToDelete" required>
<span id="isbnToDeleteError" class="error"></span> <!-- Error message container -->
<br>
<button type="submit">Delete Book</button>
</form>
<h2>Book Log</h2>
<table border="1">
<tr>
<th>ISBN</th>
<th>Title</th>
<th>Author</th>
<th>Genre</th>
</tr>
<?php
// Create connection
require_once('lib/db.php');
// Select data from Books table
$sql = "SELECT * FROM Books";
$result = $conn->query($sql);
// Output data of each row
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo "<tr>";
echo "<td>" . $row["ISBN"] . "</td>";
echo "<td>" . $row["Title"] . "</td>";
echo "<td>" . $row["Author"] . "</td>";
echo "<td>" . $row["Genre"] . "</td>";
echo "</tr>";
}
} else {
echo "<tr><td colspan='4'>0 results</td></tr>";
}
?>
</table>
<h2>Transaction Log</h2>
<table border="1">
<tr>
<th>TransactionID</th>
<th>UserID</th>
<th>InventoryID</th>
<th>TransactionType</th>
<th>TransactionDate</th>
<th>DueDate</th>
<th>Status</th>
</tr>
<?php
// Select data from Transactions table
$sql = "SELECT * FROM Transactions";
$result = $conn->query($sql);
// Output data of each row
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo "<tr>";
echo "<td>" . $row["TransactionID"] . "</td>";
echo "<td>" . $row["UserID"] . "</td>";
echo "<td>" . $row["InventoryID"] . "</td>";
echo "<td>" . $row["TransactionType"] . "</td>";
echo "<td>" . $row["TransactionDate"] . "</td>";
echo "<td>" . $row["DueDate"] . "</td>";
echo "<td>" . $row["Status"] . "</td>";
echo "</tr>";
}
} else {
echo "<tr><td colspan='7'>0 results</td></tr>";
}
?>
</table>
<h2>Inventory Log</h2>
<table border="1">
<tr>
<th>InventoryID</th>
<th>ISBN</th>
<th>TransactionID</th>
</tr>
<?php
// Select data from Inventory table
$sql = "SELECT * FROM Inventory";
$result = $conn->query($sql);
// Output data of each row
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo "<tr>";
echo "<td>" . $row["InventoryID"] . "</td>";
echo "<td>" . $row["ISBN"] . "</td>";
echo "<td>" . $row["TransactionID"] . "</td>";
echo "</tr>";
}
} else {
echo "<tr><td colspan='3'>0 results</td></tr>";
}
$conn->close();
?>
</table>
<script>
// JavaScript validation for ISBN field in Add Book form
document.getElementById('addBookForm').addEventListener('submit', function(event) {
var isbnInput = document.getElementById('isbn');
var isbnError = document.getElementById('isbnError');
if (isbnInput.value.length !== 9) {
isbnError.textContent = "ISBN must be 9 digits long";
event.preventDefault(); // Prevent form submission
} else {
isbnError.textContent = ""; // Clear error message if ISBN is valid
}
});
// JavaScript validation for ISBN field in Update Book form
document.getElementById('updateBookForm').addEventListener('submit', function(event) {
var isbnToUpdateInput = document.getElementById('isbnToUpdate');
var isbnToUpdateError = document.getElementById('isbnToUpdateError');
if (isbnToUpdateInput.value.length !== 9) {
isbnToUpdateError.textContent = "ISBN must be 9 digits long";
event.preventDefault(); // Prevent form submission
} else {
isbnToUpdateError.textContent = ""; // Clear error message if ISBN is valid
}
});
// JavaScript validation for ISBN field in Delete Book form
document.getElementById('deleteBookForm').addEventListener('submit', function(event) {
var isbnToDeleteInput = document.getElementById('isbnToDelete');
var isbnToDeleteError = document.getElementById('isbnToDeleteError');
if (isbnToDeleteInput.value.length !== 9) {
isbnToDeleteError.textContent = "ISBN must be 9 digits long";
event.preventDefault(); // Prevent form submission
} else {
isbnToDeleteError.textContent = ""; // Clear error message if ISBN is valid
}
});
</script>
</body>
</html>