This project is the prototype of a Simple Library Management System. Librarian has a provision to add book details like ISBN number, book title, author name, edition and publication details through the web page. In addition to this, librarian or any user has a provision to search for the available books in the library by the book name. If book details are present in the database, the search details are displayed on the web page.
This application is partitioned into 5 different files.
-
- To enter book details through an HTML web page – EnterBooks.php
- To insert book details into the database – InsertBooks.php
- HTML web page to enter book name to be searched – SearchBooks.php
- PHP web page to display search results – DisplayBooks.php
- Database connection details – DBConnection.php
EnterBooks.php
<!DOCTYPE HTML>
<html>
<body bgcolor="87ceeb">
<center><h2>Simple Library Management System</h2></center>
<!--Once the form is submitted, all the form data is forwarded to InsertBooks.php -->
<form action="InsertBooks.php" method="post">
<table border="2" align="center" cellpadding="5" cellspacing="5">
<tr>
<td> Enter ISBN :</td>
<td> <input type="text" name="isbn" size="48"> </td>
</tr>
<tr>
<td> Enter Title :</td>
<td> <input type="text" name="title" size="48"> </td>
</tr>
<tr>
<td> Enter Author :</td>
<td> <input type="text" name="author" size="48"> </td>
</tr>
<tr>
<td> Enter Edition :</td>
<td> <input type="text" name="edition" size="48"> </td>
</tr>
<tr>
<td> Enter Publication: </td>
<td> <input type="text" name="publication" size="48"> </td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" value="submit">
<input type="reset" value="Reset">
</td>
</tr>
</table>
</form>
</body>
</html>

Suggested Read:
Role-based Login application in PHP using MySQL
Simple Registration application in Java
InsertBooks.php
<!DOCTYPE HTML>
<html>
<body bgcolor="87ceeb">
<center><h2>Simple Library Management System</h2></center>
<br>
<?php
include("DBConnection.php");
$isbn=$_POST["isbn"];
$title=$_POST["title"];
$author=$_POST["author"];
$edition=$_POST["edition"];
$publication=$_POST["publication"];
$query = "insert into book_info(isbn,title,author,edition,publication) values('$isbn','$title','$author','$edition','$publication')"; //Insert query to add book details into the book_info table
$result = mysqli_query($db,$query);
?>
<h3> Book information is inserted successfully </h3>
<a href="SearchBooks.php"> To search for the Book information click here </a>
</body>
</html>

SearchBooks.php
<!DOCTYPE HTML>
<html>
<body bgcolor="87ceeb">
<center><h2>Simple Library Management System</h2></center>
<form action = "DisplayBooks.php" method="get">
<center>Enter the title of the book to be searched :
<input type="text" name="search" size="48">
<br></br>
<input type="submit" value="submit">
<input type="reset" value="Reset">
</center>
<br>
</form>
</body>
</html>

DisplayBooks.php
<!DOCTYPE HTML>
<html>
<body bgcolor="87ceeb">
<center><h2>Simple Library Management System</h2></center>
<br>
<?php
include("DBConnection.php");
$search = $_REQUEST["search"];
$query = "select ISBN,Title,Author,Edition,Publication from book_info where title like '%$search%'"; //search with a book name in the table book_info
$result = mysqli_query($db,$query);
if(mysqli_num_rows($result)>0)if(mysqli_num_rows($result)>0)
{
?>
<table border="2" align="center" cellpadding="5" cellspacing="5">
<tr>
<th> ISBN </th>
<th> Title </th>
<th> Author </th>
<th> Edition </th>
<th> Publication </th>
</tr>
<?php while($row = mysqli_fetch_assoc($result))
{
?>
<tr>
<td><?php echo $row["ISBN"];?> </td>
<td><?php echo $row["Title"];?> </td>
<td><?php echo $row["Author"];?> </td>
<td><?php echo $row["Edition"];?> </td>
<td><?php echo $row["Publication"];?> </td>
</tr>
<?php
}
}
else
echo "<center>No books found in the library by the name $search </center>" ;
?>
</table>
</body>
</html>

DBConnection.php
We are making use of MySQL database server in this application. The URL format and driver name going to be different for different database servers.
<?php
//Establishing connection with the database
define('DB_SERVER', 'localhost:3306');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', 'root123');
define('DB_DATABASE', 'books'); //where books is the database name
$db = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
?>

I went back to using php/mysql after more than 15 years. This example is AWESOME, clear and well explained. Thank you so much!! From Joaçaba/SC/Brasil
Great to hear that Guillermo :)
how to run this program??????????????
please help
Shekhar, you can follow the below steps.
You need to have a PHP server to PHP code. You can use wampserver software which provides an integrated environment to run PHP files along with the MySQL database server. Copy all the PHP files into wampserver.
Next, open PHP file in the browser via localhost URL. Usually http://localhost/EnterBooks.php
Enter book details and submit the data.
You can perform other operations similarly.
I am trying to import books from another application that no longer runs on the lower version of php. In trying to import it, I need an id field with Auto_Increment. since ISBN is set as Primary key in your application, how can I add the id field and what part of the code needs to be changed to incorporate the new field. Many thanks.
Hi Andrew,
It’s simple. First you need to alter the strcuture of the table – BOOK_INFO to add a placeholder for ID and define it as auto_incrment. This setting alone should suffice. Whenever a record is inserted into the table the id would auto increment.
Please try this and let me know.
Thanks.. It helped. God bless you
You are Welcome Divya.
I am glad that this helped you.
Code to sreate table in your database using phpmyadmin:
CREATE TABLE book_info (
isbn VARCHAR(30) PRIMARY KEY,
title VARCHAR(100) NOT NULL,
author VARCHAR(100) NOT NULL,
edition VARCHAR(30) NOT NULL,
publication VARCHAR(30) NOT NULL
);
Good luck!
Great. Thanks, Willem.
Hi,
Urgently required software for managing library. Please give us your email address.
Hi,
Sorry to say that we do not provide services at this moment.
Hi,
We have library management system offline. But we wanted to convert it to online with html, css etc. Is possible to convert and give.
Please if you send the code alijawadd55@gmail.com
Hi,
You can refer to the code given on this page.
how to partion file?
can you give database entries which we have to givr
Hi Betty,
The insert query can be found in InsertBooks.php file
10x bro
Sir, what about sql injections ? should we not use pdo/prepared statements as a must. i am learning php and everyone says this is must. also sir i reading an article, it says something about xss and csrf .please advise
Hi,
This example uses very basic statements.
You can refer to the following application to learn about from validations and passwords encryption.
https://krazytech.com/programs/complete-login-and-registration-application-using-php-and-mysql
sir i use tomcat to run php code and mysql server for db.inserted books is not shown in display page.why???
Hi,
Please check whether the records are present in the table. If records are present then we need to check whether fetch query is working fine or not.
how should I connect to database using oracle 10g username and password?
Hi Chaitali,
You can update the connection details in DBConnection.php. You will have to use Oracle 10g supported functions for all the DB operations.
Refer to the following link
https://www.php.net/manual/en/function.oci-connect.php
sir i’m having an issue on insert page
Warning: mysqli_query() expects at least 2 parameters, 1 given in C:\xampp\htdocs\lib\insertbooks.php on line 17
this is the error
please help
Hi,
I believe it is getting failed at insert query. Please check your database connection and the book_info table structure.
In display books i am getting error on line 11 why?
Hi,
What error do you see there?
how to create db ?
can i create it using oracle(run sql) software
This application uses the MySQL database server. Go to phpMyAdmin and create the database and table.
can i use xampp and can store my db in phpmyadmin is it possible or not please answer me
You can use phpMyAdmin to create the database and tables.
Notice:Undefined varialbe:Search on Displaybook.php
Please can u help me
Verify the following line in SearchBooks.php
Managed to? because I have the same
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\wamp64\www\librarydemo\DisplayBooks.php on line 18. any help?
Hi Jacob,
Did you connect to the MySQL database?
Did you create the table “book_info”?
Ravi, just wanted to say a big thankyou, works fine and is a great tutorial for creating and searching records!
Thankyou again
sir everything is working fine but the data is not being retrieved. I do not have sql in my system, so is it because of that?? Kindly note that no error is being shown!
Yes Zayn. You should have the SQL server and the book information needs to be inserted in that.
Hello sir plzz help me can u send me the complited code of book-shop management…
I m beginner don’t know how to connect front end to the backend plzz help sir…
Can u send the code in this mailId-pujakk911@gmail.com
sir please can uhelp me sending complete database project on library mgmt system on sql htmlphp
i can help u from any after submission i daily surf this krazytechblog
ao believe on me i need compleete code with this 5 november please try this fo r me
Hi there,
Thanks for being here.
You can refer to this article. This is complete and working code. It is very basic though.
I am beginner. i don’t know how to create table in db and connecting with db……….can u give me a solution for the above library management system……
Copy everything as is and use the table creation script to create the table.
https://krazytech.com/wp-content/uploads/2017/06/MySQL-scripts-to-create-database-and-table-for-a-Library-Management-System.jpg
Sir how many tables should i create in database?
For this application, only one table is required. You can find the script in the image.
https://krazytech.com/wp-content/uploads/2017/06/MySQL-scripts-to-create-database-and-table-for-a-Library-Management-System.jpg
then what is the use of books_info
Yes table name is book_info whereas books is the database.
sir, i need this code as fast as possible the above code is getting errors
Sudha,
It is a working code. Please check your database connectivity.
mysqli_num_rows() expects parameter 1 to be mysqli_result, null given in D:\xampp\htdocs\klu\insertbook1.php plzzz fix it bro….
Hi Sai,
In the InsertBooks code, there is only one function being used.
$result = mysqli_query($db,$query);
i.e. to insert the book details into the database.Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\WEB PROGRAMMING FOR 3rd SEm\BOOK INFO\DisplayBooks.php on line 14
Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\WEB PROGRAMMING FOR 3rd SEm\BOOK INFO\DisplayBooks.php on line 30
AccessNo Title Author Edition Publication
Sam,
Are you still facing this issue?
a bro i am beginners.. so..plz send me code to this mail id sameertech93@gmail.com
i need this hole source code its very argnt
Hi Sam,
Copy the same code as it is. It works fine.
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in what to do i dont knw brooo plzzzzzzz fix this prblm wht can i do
Hy, please if you can help me with the code for issuing book and returning books and fine calculation
enterbooks.php is a html file.there is no use of php tag(?php ?>)..why did you save it as a php file?
Hi Puja,
PHP is a server side scripting language. It executes on the server and only the output is downloaded on the client’s computer whereas the HTML is a client side scripting language and whole code is executed on the client’s computer.
It is advised to maintain uniformity while building any application.
We can extend our code anytime to display error messages set from a PHP page on to the form page. You can see this practice followed in the in Java login/registration application.
https://krazytech.com/programs/java-registration-page-using-servlet-mysql-mvc
https://krazytech.com/programs/a-login-application-in-java-using-model-view-controllermvc-design-pattern
Thank you.could you please upload the source code of how to issue books,return books,availability of books,display all these thing..
You need to alter the table and add columns like issued_date, returned_date and based on these two columns you can check for the availability.
You can refer to the following code to display book details.
https://krazytech.com/programs/a-php-program-to-save-records-retrieving-from-database-using-mysql
hello
Thank you.Could you please upload or write the source code of how to issue books,return books,availability of books,display books..
Hi Puja,
Can you try it yourself? reach out to us for doubts.