-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinsert_book.php
78 lines (73 loc) · 2.38 KB
/
insert_book.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
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = $_POST["name"];
$author = $_POST["author"];
$price = $_POST["price"];
// Database connection
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "BookList";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Insert data into database
$sql = "INSERT INTO book_list (name, author, price) VALUES ('$name', '$author', '$price')";
if ($conn->query($sql) === TRUE) {
echo "<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='UTF-8'>
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
<title>Added Book Information</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #800000;
}
.container {
max-width: 400px;
margin: 50px auto;
padding: 20px;
background-color: #fff;
border-radius: 8px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
}
.container h2 {
font-size: 24px;
margin-bottom: 20px;
color: #007bff;
}
.book-info {
border: 1px solid #ccc;
padding: 10px;
border-radius: 4px;
background-color: #fff;
margin-bottom: 20px;
}
.book-info p {
margin: 5px 0;
}
</style>
</head>
<body>
<div class='container'>
<h2>Added Book Information</h2>
<div class='book-info'>
<p><strong>Name:</strong> $name</p>
<p><strong>Author:</strong> $author</p>
<p><strong>Price:</strong> $price</p>
</div>
</div>
</body>
</html>";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
// Close database connection
$conn->close();
}
?>