<?
//初始化session
session_start();
include ('head.php');
require ('dbconnect.php');
// 如果没有登录,退出
if(!isset($_SESSION['Adm'])) {
echo "<p align=center>";
echo "<font color=#FF0000 size=5><strong><big>";
echo "管理员没有登录,请<a href='AdminLogin.php'>登录</a>!";
echo "</big></strong></font></p>";
exit();
}
?>
<html>
<body>
<?
if(!isset(getenv('show')) and !isset(getenv('lend'))) {
?>
<form name="form1" method="post" action="<?php echo $PHP_SELF ?>">
<table width="60%" border="0" cellspacing="1" cellpadding="3" align="center">
<tr>
<th colspan="2">借 书 1 登 记</th>
</tr>
<tr>
<td width="30%" height="32" align="right">图书编号:</td>
<td width="70%" height="32">
<input type="text" name="book_id" size="10">
<input type="submit" name="show" value="显示该书信息">
</td>
</tr>
</table>
</form>
<?
}
// 提交后处理
else {
// 只是显示图书详细信息
if(isset(getenv('show'))){
// 如果图书编号没填写,提示用户
$book_id_2= getenv['book_id'];
if ($book_id_2 == ""){
echo "<div align=center><font color=red>图书编号没有填写!</font></div>";
exit();
}
else {
$booksql="select * from book where id='$book_id_2'";
$bookresult=mysql_query($booksql,$conn);
$bookinfo=mysql_fetch_array($bookresult);
// 编号有误,没有这本书
if (empty($bookinfo)){
echo "<div align=center><font color=red>不存在该图书编号</font></div>";
exit();
}
else {
// 如果该书已经全部借出,提示用户
if ( $bookinfo[leave_number] <= 0 ){
echo "<div align=center><font color=red>该图书已全部借出!</font></div>";
echo "<div align=center> </div>";
echo "<div align=center><a href=borrow.php>继续添加</a></div>";
exit();
}
// 显示该书详细信息
?>
<form name="form2" method="post" action="borrow.php">
<table width="60%" border="0" cellspacing="1" cellpadding="3" align="center">
<tr>
<th colspan="2">借 书 2 登 记</th>
</tr>
<tr>
<td width="30%" height="32" align="right">图书编号:</td>
<td width="70%" height="32">
<input type="text" name="book_id_2" value="<? echo $bookinfo[id];?>">
<input type="hidden" name="title" value="<? echo $bookinfo[title];?>">
<input type="hidden" name="leave" value="<? echo $bookinfo[leave_number];?>">
</td>
</tr>
<tr>
<td width="30%" align="right">书名:</td>
<td width="70%"><? echo $bookinfo[title];?></td>
</tr>
<tr>
<td width="30%" align="right">作者:</td>
<td width="70%"><? echo $bookinfo[author];?></td>
</tr>
<tr>
<td width="30%" align="right">出版社:</td>
<td width="70%"><? echo $bookinfo[publisher];?></td>
</tr>
<tr>
<td width="30%" align="right">出版年份:</td>
<td width="70%"><? echo $bookinfo[publish_year];?></td>
</tr>
<tr>
<td height="23" align="right">总共:<? echo $bookinfo[total];?>本;</td>
<td height="23">库存剩余:<? echo $bookinfo[leave_number];?>本</td>
</tr>
<tr>
<td width="30%" align="right">借阅用户ID:</td>
<td width="70%">
<input type="text" name="user_id" size="10">
</td>
</tr>
<tr>
<td width="30%" align="right">
<input type="submit" name="lend" value="借出">
</td>
<td width="70%">
<input type="reset" name="Submit2" value="重置">
</td>
</tr>
</table>
</form>
<?
}
}
}
// 借书
if(isset(getenv('lend'))){
// 查看用户ID是否已填
$user_id = getenv('user_id');
$book_id_3 = getenv('book_id_2');
$title = getenv('title');
$leave = getenv('leave');
if ($user_id==""){
echo "<div align=center><font color=red>用户ID没有填写!</font></div>";
exit();
}
else {
$seachsql = "select * from lend where user_id ='$user_id'";
$seachresult = mysql_query($seachsql,$conn);
while($seachrow = mysql_fetch_array($seachresult)) {
if($book_id_3 == $seachrow['book_id']){
echo "<div align=center> </div>";
echo "<div align=center> </div>";
echo "<div align=center><font color=red>你已经借过本书,尚未归还,无法再借!</font></div>";
echo "<div align=center> </div>";
echo "<div align=center><a href=borrow.php>继续添加</a></div>";
exit();
}
else next;
}
// 可以正常借书,记录之
// 获得当前日期
$now = date("Y-m-d");
$lendsql="insert into lend(book_id, book_title, lend_time, user_id) values('$book_id_3','$title','$now','$user_id')";
mysql_query($lendsql,$conn) or die ("操作失败:".mysql_error());
// 还需要在log中记录
$logsql="insert into lend_log(book_id,user_id,lend_time) values('$book_id_3','$user_id','$now')";
mysql_query($logsql,$conn) or die ("记录失败:".mysql_error());
// 借出后需要在该书记录中库存剩余数减一
$leave_num=$leave - 1;
mysql_query("update book set leave_number='$leave_num' where id='$book_id_3'",$conn);
echo "<p align=center> </p>";
echo "<p align=center><font color=red>借阅登记完成!</p>";
echo "<p align=center><a href=borrow.php>继续添加</a></p>";
}
}
}
?>
</body>
</html>
libs_linux.rar_php 图书馆_php图书馆_php图书馆管理_图书管理_图书馆php
版权申诉
100 浏览量
2022-09-20
14:04:44
上传
评论
收藏 15KB RAR 举报
寒泊
- 粉丝: 75
- 资源: 1万+
最新资源
- MATLAB大数据仿真案例-蚁群算法(ACO)用于求解旅行商(TSP)问题.rar
- MySQL基础知识-个人笔记.rar
- Project8.ipynb
- Python实现BWO-LSTM白鲸算法优化长短期记忆神经网络时间序列预测(完整源码和数据)
- C语言实现文件读写操作的几种常用方法-C 语言.rar
- RK 3568 Android11 版本的梯形校正补丁
- 基于pyqt yolov5 dlib的驾驶员行为监控系统源码+模型.zip
- python代码案例详解-旅行商问题的多种求解算法.rar
- 单相电力电子负载仿真,PWM整流+单相并网逆变
- C语言功能模块(配置文件读取 、debug日志记录等).zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈