-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnewbookinfo.php
More file actions
57 lines (43 loc) · 1.59 KB
/
newbookinfo.php
File metadata and controls
57 lines (43 loc) · 1.59 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
<html>
<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, '3306');
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// prepare and bind
$stmt_info = $conn->prepare("INSERT INTO book_info (ISBN, title, author, edition, year_published, publisher, genre, pages) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
$stmt_info->bind_param("sssiissi", $isbn, $title, $author, $edition, $year_published, $publisher, $genre, $pages);
// set parameters and execute
$isbn = $_POST["isbn"];
$title = $_POST["title"];
$author = $_POST["author"];
$edition = $_POST["edition"];
$year_published = $_POST["year_published"];
$publisher = $_POST["publisher"];
$genre = $_POST["genre"];
$pages = $_POST["pages"];
$stmt_info->execute();
$stmt_info->close();
$stmt_copy = $conn->prepare("INSERT INTO book_copy (ISBN) VALUES (?)");
$stmt_copy->bind_param('i', $isbn);
$isbn = $_POST["isbn"];
$stmt_copy->execute();
$stmt_copy->close();
echo "New book successfully added! </br> </br>";
echo "ISBN: " . $_POST["isbn"]. "<br>Title: " . $_POST["title"]. "<br> Author: " . $_POST["author"]. "<br> Year Published:" . $_POST["year_published"]. "<br> Publisher:" . $_POST["publisher"]. "<br> Genre:" . $_POST["genre"]. "<br> Pages:" . $_POST["pages"]."<br><br>";
$conn->close();
?>
<form action="index.php">
<input type="submit" value="Return Home" />
</form>
</body>
</html>