-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnewbook.php
68 lines (54 loc) · 1.96 KB
/
newbook.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
<html>
<head>
<link rel="stylesheet" href="style.css"></link>
</head>
<body>
<h4>Add a New Book to the Library</h4>
<?php
$host = 'localhost';
$dbname = 'library-database';
$username = 'root';
$password = '';
//$password = 'Password1';
// Create connection
$conn = new mysqli($host, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$isbn = $_POST["isbn"];
$sql = "SELECT * FROM book_info WHERE ISBN = '$isbn'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
echo "The book already exists in the library database: <br>";
$row = $result->fetch_assoc();
echo "ISBN: " . $row["ISBN"]. "<br>Title: " . $row["title"]. "<br> Author: " . $row["author"]. "<br> Year Published:" . $row["year_published"]. "<br> Publisher:" . $row["publisher"]. "<br> Genre:" . $row["genre"]. "<br> Pages:" . $row["pages"]."<br><br>";
$stmt = $conn->prepare("INSERT INTO book_copy (ISBN) VALUES (?)");
$stmt->bind_param('s', $isbn);
$isbn = $_POST["isbn"];
$stmt->execute();
$stmt->close();
echo "A copy of the book has been added to the library.";
} else {
echo "The book is new, please enter the following details:";
?>
<form action="newbookinfo.php" method="post">
ISBN: <input type="text" name="isbn" value=<?php echo $_POST["isbn"];?> required><br>
Title: <input type="text" name="title" required><br>
Author: <input type="text" name="author"><br>
Edition: <input type="number" name="edition"><br>
Year Published: <input type="number" name="year_published"><br>
Publisher: <input type="text" name="publisher"><br>
Genre: <input type="text" name="genre"><br>
Pages: <input type="number" name="pages"><br>
<input type="submit" class="clickButton" />
<?php
}
$conn->close();
?>
<form action="index.php">
<input type="submit" value="Return Home" class="clickButton" />
</form>
</body>
</html>