Im trying to create a library management system wherein there is an allbooks table and a borrowedbooks table. When someone clicks borrow a book they have to enter the book ID. so when they do that I want the system to go into the all books table, check the number of books available for that book ID, -1 from the quantity and issue the book if there are any or to display a message like sorry no more books if the amount is 0. Im looking for some sort of coding structure to help me execute this in the system because I keep getting errors with my current code. I am very new to php.
What I have tried:
include("dbcon.php");
if(isset($_POST["submit3"]))
{
if
$sql = mysqli_query("SELECT bid, bstatus FROM Allbooks WHERE bid = '$_POST[bid]';");
if (!$sql) {
echo 'Could not run query: ' . mysql_error();
exit;
}
$row = mysql_fetch_row($result);
echo $row[0]; // 42
echo $row[1]; // the email value
if $row[0] > 0{
$uid = $_POST["uid"];
$bid = $_POST["bid"];
$bdate = $_POST["bdate"];
$query = "insert into Borrowedbooks(uid,bid,borroweddate) values('$uid','$bid','$bdate')"; //Insert query to add book details into the book_info table
$result = mysqli_query($conn,$query);
}
echo" Sorry there are no more copies";