I'm trying to build a database for a bookstore with 3 tables: Book, Volume and Publication. I'm using mysqli() and the code neither works nor echoes any errors.
<?php
//connect to db
$conn = new mysqli("localhost", "root", "", "ershadbookstore");
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
#new recoed: if the new record is inserted into book successfully, another new record is inserted into volume table. the same goes for volume and phblication table. at the end the total number of this volumn is editted in the rows with the same isbn.
$sql = "INSERT INTO Book (name, vnum, writer, translator, publisher, genre, format)
VALUES ('test', 'test', 'test', 'test', 'test', 'test', 'test')";
if ($conn->query($sql) === TRUE) {
$last_bid = $conn->insert_id;
$sql = "INSERT INTO Volume (isbn, bid, vnum, note, image)
VALUES ('test', 'test', 'test', 'test', 'test')";
if ($conn->query($sql) === TRUE) {
$sql = "INSERT INTO Publication (isbn, pubnum, pyear, circulation, fpyear, pnum, price, num)
VALUES ('test', 'test', 'test', 'test', 'test', 'test', 'test', 'test')";
if ($conn->query($sql) === TRUE) {
$sql= "SELECT SUM(num) FROM Publication
WHERE (isbn='test')";
if ($conn->query($sql) === TRUE) {
$totalNum=$conn->query($sql);
$sql1= "UPDATE Volume
SET (tnum = test)
WHERE (isbn= test)";
if ($conn->query($sql1) === TRUE)
{
echo "true";
}
else
{
return "Error publication table: " . $sql1 . "<br>" . $conn->error;
}
}
}
else{
return "Error publication table: " . $sql . "<br>" . $conn->error;
}
}
else {
return "Error for volume table: " . $sql . "<br>" . $conn->error;
}
}
else {
return "Error for book table: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>