Borrowing and Returning Function in PHP/MySQL

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');
  3.  
  4. require ('session.php');
  5.  
  6. $id = $_POST['selector'];
  7. $client_id = $_POST['client_id'];
  8.  
  9. if ($id == '')
  10. {
  11. header("location: release.php");
  12. ?>
  13.  
  14.  
  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. }
  32.  
  33. header("location: release.php");
  34. }
  35.  
  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.

Comments

Submitted byjohn mwangi (not verified)on Wed, 09/27/2017 - 16:22

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

Add new comment