-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbooks.php
More file actions
70 lines (63 loc) · 2.03 KB
/
Copy pathbooks.php
File metadata and controls
70 lines (63 loc) · 2.03 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
<?php
session_start();
// Check if the user is an admin
if (!isset($_SESSION['user_type']) || $_SESSION['user_type'] != 'admin') {
header('Location: login.php');
exit();
}
// Database connection
$conn = new mysqli('localhost', 'root', '', 'dbms');
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Fetch all books from the database
$sql = "SELECT * FROM books";
$result = $conn->query($sql);
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="styles.css">
<title>Manage Books (Admin)</title>
</head>
<body>
<div class="sidebar">
<h2 class="menu" style="color:#3BABF6">ADMIN MENU</h2>
<a href="admin_dashboard.php">Admin Dashboard</a>
<a href="add_user.php">Add User</a>
<a href="add_book.php">Add Book</a>
<a href="admin_cart.php">View Cart Requests</a>
<a href="orders.php">View Orders</a>
<form method="POST" action="admin_dashboard.php">
<button type="submit" name="signout" class="button signout">Sign Out</button>
</form>
</div>
<h1>Available Books (Admin)</h1>
<div class="container">
<table class="table">
<tr>
<th>Book ID</th>
<th>Title</th>
<th>Price</th>
<th>Quantity</th>
<th>Available</th>
<th>Author</th>
</tr>
<?php while($row = $result->fetch_assoc()): ?>
<tr>
<td><?php echo $row['book_id']; ?></td>
<td><?php echo htmlspecialchars($row['title']); ?></td>
<td><?php echo htmlspecialchars($row['price']); ?></td>
<td><?php echo htmlspecialchars($row['quantity']); ?></td>
<td><?php echo htmlspecialchars($row['available']); ?></td>
<td><?php echo htmlspecialchars($row['author']); ?></td>
</tr>
<?php endwhile; ?>
</table>
</div>
</body>
</html>
<?php
$conn->close(); // Close the database connection
?>