-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathavailablebooks.php
More file actions
154 lines (147 loc) · 4.22 KB
/
availablebooks.php
File metadata and controls
154 lines (147 loc) · 4.22 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
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
<?php
session_start();
// Database configuration
$servername = "localhost:3307";
$username = "root";
$password = "venessa33";
$dbname = "librarymain";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if (isset($_SESSION['email'])) {
$email = $_SESSION['email'];
// Use the $email variable as needed
} else {
// Handle the case where the email is not set in the session
echo "User not logged in.";
}
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['borrow'])) {
$bookId = $_POST['bookid'];
$sql = "INSERT INTO borrowrequest (bookid,email, borrowstatus) VALUES ('$bookId', '$email', 'pending')";
if ($conn->query($sql) === TRUE) {
echo "Request to borrow book has been sent.";
} else {
echo "Error: " . $conn->error;
}
}
// SQL query to select available books
$sql = "SELECT bookid, BookName, AuthorID FROM books WHERE Bookstatus = 'available'";
$result = $conn->query($sql);
// Initialize counter for available books
$availableCount = 0;
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<style>
body{
align-items: center;
justify-content: center;
font-family: sans-serif;
background: #f3f3f3;
flex-direction: column;
margin: 0;
}
.header{
text-transform: uppercase;
font-family: 'Times New Roman', Times, serif;
text-align: center;
color:black;
font-style:italic;
background-color:lightblue;
margin-top:-45px;
height:80px;
padding-top:30px
}
.nav{
background-color:lightblue;
margin:
}
.nav a{
color:black;
display:inline-block;
text-align:center;
padding: 25px;
padding-left:100px;
}
.nav a:hover{
text-decoration: underline;
color:blue;
}
button{
background-color:brown;
border: none;
color:white;
text-align: center;
font-size:16px;
border-radius:20px;
padding:10px;
}
button:hover{
background-color:blueviolet;
}
table {
width:100%;
border-collapse: collapse;
}
table, th, td {
border: 2px solid black;
}
th, td {
padding: 20px;
text-align: left;
}
.h1{
text-align: center;
}
</style>
</head>
<body>
<div class="header">
<h1> LIBRARY MANAGEMENT SYSTEM</h1>
</div>
<div class="nav">
<a href="userhomepage.php">DASHBOARD</a>
<a href="availablebooks.php">AVAILABLE BOOKS TO BORROW </a>
<a href="borrowedbooks.php"> ISSUED BOOKS</a>
<a href="userlogoutpage.php">
<button>Log Out</button>
</a>
</div>
<div class="h1">
<h1>Available Books</h1>
</div>
<table>
<tr>
<th>BookName</th>
<th>AuthorID</th>
<th>Action</th>
</tr>
<?php
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
echo "<tr>
<td>{$row['BookName']}</td>
<td>{$row['AuthorID']}</td>
<td>
<form method='POST'>
<input type='hidden' name='bookid' value='{$row['bookid']}'>
<button type='submit' name='borrow'>Borrow</button>
</form>
</td>
</tr>";
$availableCount++;
}
} else {
echo "<tr><td colspan='3'>No books available</td></tr>";
}
?>
</table>
<p>Number of available books: <?php echo $availableCount; ?></p>
<?php $conn->close(); ?>
</body>
</html>