Borrowing and Returning Function in PHP/MySQL

Submitted by: 
Visitors have accessed this post 12590 times.

In this tutorial, we are going to learn how to create Borrowing and Returning Function in PHP/MySQL. We all know, Library System have this two functions. You can use this source code to create a simple Library System or in any system that has to borrow and returning functions. Hope you can learn from this tutorial. Enjoy coding.

Account information

  • Username: admin
  • Password: admin

Here’s the to-do list

  • Borrowed Items
  • Returned Items

Sample Source Code

This sample PHP query is for the borrowing function.

  1. <?php
  2. require ('include/database.php');
  4. require ('session.php');
  6. $id = $_POST['selector'];
  7. $client_id = $_POST['client_id'];
  9. if ($id == '')
  10. {
  11. header("location: release.php");
  12. ?>
  15. <?php
  16. }
  17. else
  18. {
  19. mysql_query("insert into tbl_release (client_id,date_borrow) values ('$client_id',NOW()) ") or die(mysql_error());
  20. $query = mysql_query("select * from tbl_release order by release_id DESC") or die(mysql_error());
  21. $row = mysql_fetch_array($query);
  22. $release_id = $row['release_id'];
  23. $history_record = mysql_query("select * from user where user_id=$id_session");
  24. $row1 = mysql_fetch_array($history_record);
  25. $user = $row1['firstname'] . " " . $row1['lastname'];
  26. $N = count($id);
  27. for ($i = 0; $i < $N; $i++)
  28. {
  29. mysql_query("INSERT INTO transaction_history (item_id,action,client_id,release_id,admin_name,date_added) VALUES ('$id[$i]','Borrowing Item','$client_id','$release_id','$user',NOW())") or die(mysql_error());
  30. mysql_query("insert into release_details (item_id,release_id,release_status) values ('$id[$i]','$release_id','pending')") or die(mysql_error());
  31. }
  33. header("location: release.php");
  34. }
  36. ?>

Related Code:

How to Make Library System

Library Management System with Barcode

If you have a question for this tutorial, don't to hesitate to ask, kindly leave your comment below. Thank you.


May I ask the full version of this. please send [email protected]

May I request to upload the complete version to my email [email protected]

Is the source code able to avoid double borrowing , or removing the book once borrowed.iv not how can one code this ...

clicking the Barrow button in releasing page is not working.. pls help..

need it urgent please... [email protected]

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.