A Library System with PHP

Hello again. In this article i will explain how to write a web interface with PHP, JavaScript, MySQL, CSS and HTML.

This project is developed by using WAMP server. It is a very useful tool that combines Apache, MySQL and PHP servers in which everybody can install easily and do some useful work.

First of all, we need to start all the services after installing WAMP server. After that it will be placed like following;Screenshot (2)

localhost bar will take you directly for php projects. phpmyadmin will be for phpmyadmin to control the database and the flow of data. www directory will be the place that php project files will be held in. Press start all services button.

For PHP, an editor is needed. For that reason, i used CodeLobster software to compile by code but Notepad++ or other compilers will also work. It will be enough just to place that file in the www directory after all the coding is done.

The user guide about the website can be found in here. Besides that i will explain in detail how i writed the code.

First of all, we need to connect MySQL and PHP. That is quite easy, we just have to enter some parameters about our connection information(username and password for MySQL) and the name of our database which includes our tables like following;


Screenshot (3)

data.php is to be used whenever a query is needed to be executed for inserting, deleting or updating the informations about the student and books.

Next, we need to design our main page. In the main page, all the students are listed and all the operations can be done by clicking the buttons. The interface is like following;

Screenshot (4)


All the operations listed are possible with the library system. Every single operation is done by queries and their execution with some PHP and JavaScript codes. I have 3 tables. One is to hold students’ attributes and the other one is to hold books’ values, last one is to keep every students’ book name with student’s id.

For adding a book button,it adds into the book table but if we want to add a book to a student, we have to insert the book into the database first. A student can pick any book from the listed books. If a student is going to get a book, return a book or is to be printed all the books, edit must be clicked to get to the operations part. It is like following;

Screenshot (5)

The code of that is like following;

Screenshot (6)

This is the code for choosing the operation. Link is to get the themes for the interface(green and blue colors, changed size of text boxes,etc.). At form, we implicitly indicate that we will be using a variable in the code in “adding_book.php” page and we will do that by using “$_GET[‘<variable_name>’]” declaration. $student_id is received with that way from the edit.php page and that value returns the student that was chosen from the list at the main page. We will be sending this value to adding_book.php page to use to add into the database with the name of the book. That method is used through every php page since variables are important and they are needed for making the operations.

If we click on “ADD BOOK”, we will be facing with a screen that shows the book names that are available for the student. By choosing that, student will be added with its id and with that book name into the studentbook table and when necessary, we will get the books of that specific student.

We can also delete a book from the student with the same method, the only difference will be in the query. Instead of using insert, we will be using delete.

Screenshot (7)

As can be seen in here, both the variables are reached by get method and they will be inserted into student like following;

Screenshot (8)

The logic is all the same for all every other procedures. It is all about writing simple queries, passing them as parameters into PHP functions and making them work in an efficient way.

That will be all for this project. The other party of the code can be reached here.I would be very glad with every questions or corrections. Happy codings!







Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s