-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadd_book.php
32 lines (28 loc) · 993 Bytes
/
add_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
<?php
// Create connection
require_once('lib/db.php');
// Check if form is submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Retrieve form data
$title = $_POST["title"];
$author = $_POST["author"];
$genre = $_POST["genre"];
$isbn = $_POST["isbn"];
$transactionID = $_POST["transactionID"];
// SQL to insert new book
$sql_book = "INSERT INTO Books (ISBN, Title, Author, Genre) VALUES ('$isbn', '$title', '$author', '$genre')";
if ($conn->query($sql_book) === TRUE) {
echo "New book added successfully";
// SQL to insert new inventory entry with the same ISBN
$sql_inventory = "INSERT INTO Inventory (ISBN,TransactionID) VALUES ('$isbn','$transactionID')";
if ($conn->query($sql_inventory) === TRUE) {
echo " and added to inventory successfully";
} else {
echo "Error adding book to inventory: " . $sql_inventory . "<br>" . $conn->error;
}
} else {
echo "Error adding book: " . $sql_book . "<br>" . $conn->error;
}
}
// Close connection
$conn->close();