PHP develops the home page borrowing function of a simple book borrowing system

As shown in the picture

3.png

There is an operation directory under the operation bar on the main page that displays "I want to borrow books"

After clicking it, you can Start implementing the book borrowing function. If the current quantity is displayed as 0,

This column will be "The book has been borrowed". You cannot click to select this item.

1617.png

First determine whether the book number id has been filled in. If not, the user will be prompted

<?php
$book_id = $_GET['book_id'];
if ($book_id==""){
   echo "<script language=javascript>alert('编号不正确');window.location='index.php'</script>";
   exit();
}
?>

to check whether the user is logged in. If not logged in, the book cannot be borrowed

Record the current date after the user logs in to borrow a book

After a book is borrowed, the inventory of this book needs to be reduced by one

<?php
// 借书
// 查看用户ID是否已填
if ($_SESSION['id']==""){
   echo "<script language=javascript>alert('您还没有登陆');window.location='landing.php'</script>";
   exit();
}else{
   // 可以正常借书,记录id
   // 获得当前日期
   $now = date("Y-m-d,H-i-m");
   $lendsql="INSERT INTO lend(book_id, book_title, lend_time, user_id) values('$book_id','$title','$now','".$_SESSION['id']."')";
   mysqli_query($link,$lendsql);

   // 借出后需要在该书记录中库存剩余数减一
   mysqli_query($link,"update yx_books set leave_number=leave_number-1 where id='$book_id'");
   echo "<script language=javascript>alert('借阅完成');window.location='index.php'</script>";
  }
?>


Continuing Learning
||
<?php // 可以正常借书,记录id // 获得当前日期 $now = date("Y-m-d,H-i-m"); $lendsql="INSERT INTO lend(book_id, book_title, lend_time, user_id) values('$book_id','$title','$now','".$_SESSION['id']."')"; mysqli_query($link,$lendsql); // 借出后需要在该书记录中库存剩余数减一 mysqli_query($link,"update yx_books set leave_number=leave_number-1 where id='$book_id'"); ?>
submitReset Code