I am building a library management system using PHP, JavaScript. Each book has a unique code. There will be a system in the form of book borrowing pages. If you input the code of any book, the name of the book and the quantity of the book will come down. I was able to get the name of the book using JavaScript. But I could not bring the amount of books.
issue-book.php
function getbook() {
$("#loaderIcon").show();
jQuery.ajax({
url: "get_book.php",
data:'bookid='+$("#bookid").val(),
type: "POST",
success:function(data){
$("#get_book_name").html(data);
$("#loaderIcon").hide();
},
error:function (){}
});
}
//function for quantity
function getquantity() {
$("#loaderIcon").show();
jQuery.ajax({
url: "get_quantity.php",
data:'bookid2='+$("#bookid2").val(),
type: "POST",
success:function(data){
$("#get_quantity").html(data);
$("#loaderIcon").hide();
},
error:function (){}
});
}
</script>
<style type="text/css">
.others{
color:red;
}
</style>
</head>
<body>
<!------MENU SECTION START-->
<?php include('includes/header.php');?>
<!-- MENU SECTION END-->
<div class="content-wra
<div class="content-wrapper">
<div class="container">
<div class="row pad-botm">
<div class="col-md-12">
<h4 class="header-line">Issue a New Book</h4>
</div>
</div>
<div class="row">
<div class="col-md-10 col-sm-6 col-xs-12 col-md-offset-1"">
<div class="panel panel-info">
<div class="panel-heading">
Issue a New Book
</div>
<div class="panel-body">
<form role="form" method="post">
<div class="form-group">
<label>Student id<span style="color:red;">*</span></label>
<input class="form-control" type="text" name="studentid" id="studentid" onBlur="getstudent()"
autocomplete="off" required />
</div>
<div class="form-group">
<span id="get_student_name" style="font-size:16px;"></span>
</div>
<div class="form-group">
<label>ISBN Number or Book Title<span style="color:red;">*</span></label>
<input class="form-control" type="text" name="booikid" id="bookid" onBlur="getquantity()"
required="required" />
</div>
<div class="form-group">
<select class="form-control" name="bookdetails" id="get_book_name" readonly></select>
</div>
<div class="form-group">
<select class="form-control" name="quantity" id="get_quantity" readonly></select>
</div>
<button type="submit" name="issue" id="submit" class="btn btn-info">Issue Book </button>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
get_quantity.php
<?php
require_once("includes/config.php");
if(!empty($_POST["bookid2"])) {
$bookid2=$_POST["bookid2"];
$sql ="SELECT Quantity, id FROM tblbooks WHERE (ISBNNumber=:bookid2)";
$query= $dbh -> prepare($sql);
$query-> bindParam(':bookid2', $bookid2, PDO::PARAM_STR);
$query-> execute();
$results = $query -> fetchAll(PDO::FETCH_OBJ);
$cnt=1;
if($query -> rowCount() > 0)
{
foreach ($results as $result) {?>
<option value="<?php echo htmlentities($result->id);?>"><?php echo htmlentities($result-
>Quantity);?></option>
<b>Book Name :</b>
<?php
echo htmlentities($result->Quantity);
echo "<script>$('#submit').prop('disabled',false);</script>";
}
}
else{?>
<option class="others"> Invalid ISBN Number</option>
<?php
echo "<script>$('#submit').prop('disabled',true);</script>";
}
}
?>
