-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_book.php
More file actions
70 lines (63 loc) · 2.33 KB
/
Copy pathadd_book.php
File metadata and controls
70 lines (63 loc) · 2.33 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();
if (!isset($_SESSION['email']) || $_SESSION['user_type'] != 'admin') {
header('Location: login.php');
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$title = $_POST['title'];
$price = $_POST['price'];
$quantity = $_POST['quantity'];
$available = $_POST['available'];
$author = $_POST['author'];
// Database connection
$conn = new mysqli('localhost', 'root', '', 'dbms');
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Insert book into the database
$sql = "INSERT INTO books (title, price, quantity, available, author) VALUES ('$title', '$price', '$quantity', '$available', '$author')";
if ($conn->query($sql) === TRUE) {
echo "New book added successfully.";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
}
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="styles.css">
<title>Add Book</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="user.php">Manage Users</a>
<a href="books_admin.php">Manage Books</a>
<a href="admin_cart.php">View Cart</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>Add New Book</h1>
<div class="container">
<form method="POST" action="add_book.php">
<label for="title">Title:</label>
<input type="text" id="title" name="title" required><br><br>
<label for="price">Price:</label>
<input type="number" id="price" name="price" required><br><br>
<label for="quantity">Quantity:</label>
<input type="number" id="quantity" name="quantity" required><br><br>
<label for="available">Available:</label>
<input type="number" id="available" name="available" required><br><br>
<label for="author">Author:</label>
<input type="text" id="author" name="author" required><br><br>
<button type="submit" class="button">Add Book</button>
</form>
</div>
</body>
</html>