-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddreversation.php
More file actions
159 lines (139 loc) · 4.47 KB
/
Copy pathAddreversation.php
File metadata and controls
159 lines (139 loc) · 4.47 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
155
156
157
158
159
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "library";
$connection = mysqli_connect($servername, $username, $password , $dbname);
if (!$connection) {
die("Connection failed: " . mysqli_connect_error());
}
$userQuery = "SELECT UserID, UserName FROM user";
$userResult = mysqli_query($connection, $userQuery);
$bookQuery = "SELECT BookID, Title FROM book";
$bookResult = mysqli_query($connection, $bookQuery);
// Handle form submission
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$UserID = $_POST["UserID"];
$BookID = $_POST["BookID"];
$ReturnDate = $_POST["ReturnDate"];
// Insert record into borrow table
$query = "INSERT INTO `reversation`(`UserID`, `BookID`,`ReturnDate`)
VALUES ('$UserID', '$BookID', '$ReturnDate')";
if (mysqli_query($connection, $query)) {
echo "<script>
alert('Record inserted successfully!');
window.location.href = 'reservation.php';
</script>";
} else {
echo "Error: " . $query . "<br>" . mysqli_error($connection);
}
}
mysqli_close($connection);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Borrow Book Form</title>
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap" rel="stylesheet">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Poppins', sans-serif;
background-color: #f4f7fc;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
}
.form-container {
width: 100%;
max-width: 500px;
background-color: #fff;
border-radius: 8px;
padding: 20px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}
h1 {
font-size: 2rem;
margin-bottom: 20px;
text-align: center;
color: #333;
}
.form-group {
margin-bottom: 15px;
}
label {
font-size: 1rem;
color: #333;
margin-bottom: 5px;
display: block;
}
select,
input[type="date"] {
width: 100%;
padding: 10px;
font-size: 1rem;
border: 1px solid #ccc;
border-radius: 5px;
}
button[type="submit"] {
background-color: #007bff;
color: white;
border: none;
padding: 12px 20px;
font-size: 1rem;
border-radius: 5px;
cursor: pointer;
width: 100%;
}
button[type="submit"]:hover {
background-color: #0056b3;
}
@media (max-width: 768px) {
.form-container {
width: 90%;
}
}
</style>
</head>
<body>
<div class="form-container">
<h1>Borrow a Book</h1>
<form method="POST">
<div class="form-group">
<label for="UserID">User ID:</label>
<select id="UserID" name="UserID" required>
<option value="">Select User</option>
<?php while ($user = mysqli_fetch_assoc($userResult)): ?>
<option value="<?php echo $user['UserID']; ?>">
<?php echo $user['UserName']; ?>
</option>
<?php endwhile; ?>
</select>
</div>
<div class="form-group">
<label for="BookID">Book ID:</label>
<select id="BookID" name="BookID" required>
<option value="">Select Book</option>
<?php while ($book = mysqli_fetch_assoc($bookResult)): ?>
<option value="<?php echo $book['BookID']; ?>">
<?php echo $book['Title']; ?>
</option>
<?php endwhile; ?>
</select>
</div>
<div class="form-group">
<label for="ReturnDate">Return Date:</label>
<input type="date" id="ReturnDate" name="ReturnDate" required>
</div>
<button type="submit" class="submit-btn">Submit</button>
</form>
</div>
</body>
</html>