ps:前端页面设计得有点丑,将就着用,哈哈哈。不具备用户和管理员功能,如要实现只需将首页的功能根据数据库中账号信息选择性使用就可以了。数据库关系设计什么的完全没考虑
(借图)
XAMPP
很好用且免费,下载地址, 附 一篇安装和配置的博文
Dreamweaver
很好用但正版要付费
可以直接在里面设置站点信息,然后可以直接在浏览器中打开
SQLyog
一个好用的数据库管理软件,下载地址
这个可以自己来
成为一员(类似于注册会员)
思路: html表单通过post方法向php文件传递两个参数,id和姓名,php文件接受数据后与数据库建立连接,向用户表中插入数据。用户表中available项用于标识是否有借阅资格,默认为1,借书超过期限后设置为0,下一次借书前会检查该项的值,如果为0将不会有资格借书
reader表
reader_id+reader_name+available
<html>
<head>
<meta charset="utf-8">
<title>to be a readertitle>
head>
<body>
<form method="post" action="addreader.php">
编号(reader_id):<input type="text" name="id" size="10"><br>
姓名(reader_name):<input type="text" name="name" size="30">
<input type="submit" name="join" value="加入"><br><br>
<a href="homepage.html">回主页a>
form>
body>
html>
addreader.php
$host = 'localhost';
$username = '';//数据库用户名
$password = '';//数据库密码
$dbname = '';//保存数据的数据库名称
$id = $_POST['id'];
$name = $_POST['name'];
$mysql = new mysqli($host, $username, $password, $dbname);
if ($mysql->connect_errno) {
die('数据库连接失败:' . $mysql->connect_errno);
} else {
$mysql->set_charset('UTF-8'); // 设置数据库字符集
$sql = "INSERT INTO reader (reader_id,reader_name) VALUES ('$id','$name')"; // SQL 语句
$result = $mysql->query($sql);
if ($result)
echo "";
else echo "Failed to add, back to add again.
";
$mysql->close();
}
?>
<a href="readerinfo.html">继续加入</a> 或者 <a href="homepage.html">回到首页</a>
采购书籍
网页端
数据库中bookinfo表
book_id+book_title+author+on_shelf+num
on_shelf表示是否在架,添加时默认值为“是”
代码 addbook.html
<html>
<head>
<meta charset="utf-8">
<title>Add booktitle>
head>
<body>
<form method="post" action="addbook.php">
设置书号(book_id):<input type="text" name="id" size="5"><br>
书名(book_title):<input type="text" name="name" size="30"><br>
作者(author):<input type="text " name="author" size="20"><br>
数量(num):<input type="number" min="1" name="num">
<input type="submit" name="add" value="添加"><br>
form>
body>
html>
addbook.php
$host = 'localhost';
$username = '';//数据库用户名
$password = '';//数据库密码
$dbname = '';//用于保存数据的数据库
$mysql = new mysqli($host, $username, $password, $dbname);
$title = $_POST['name'];
$title_id = $_POST['id'];
$author = $_POST['author'];
$num = $_POST['num'];
if ($mysql->connect_errno) {
die('数据库连接失败:' . $mysql->connect_errno);
} else {
$sql = "INSERT into bookinfo (book_id,book_title,author,num)
values ('$title_id','$title','$author',$num)";
$result = $mysql->query($sql);
if ($result)
echo "";
else echo "Failed to add, back to add again.
";
$mysql->close();
}
?>
<br>
<a href="addbook.html">返回继续添加</a> or <a href="homepage.html">返回首页</a>
查看书籍
思路: 在php文件中加入html内容,用于将查询到的数据以表格的形式显示出来
代码 allbook.php
$host = 'localhost';
$username = '';
$password = '';
$dbname = '';
$mysql = new mysqli($host, $username, $password, $dbname);
if ($mysql->connect_errno) {
die('数据库连接失败:' . $mysql->connect_errno);
} else {
$sql = "select * from bookinfo";
$result = $mysql->query($sql);
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>All Information</title>
</head>
<body>
<table width="800px" border="1" style="border-collapse: collapse;">
<thead>
<th>书号</th>
<th>书名</th>
<th>作者</th>
<th>是否可借</th>
<th>现存量</th>
</thead>
while ($row = mysqli_fetch_row($result)) {
?>
<tr>
<td align="center"> echo $row[0]; ?></td>
<td align="center"> echo $row[1]; ?></td>
<td align="center"> echo $row[2]; ?></td>
<td align="center"> echo $row[3]; ?></td>
<td align="center"> echo $row[4]; ?></td>
</tr>
}
?>
</table>
<br>
<a href="homepage.html">返回首页</a>
</body>
</html>
借阅书籍
思路: 首先根据读者id确认是否有资格进行借阅,readerinfo表中不存在记录或者存在记录但available项为0时,没有资格借阅,将回到主页,可以选择成为一员功能添加用户信息,再进行借阅,但是对于借书不还的来添加信息后继续借阅,没办法,哎。若有资格将进入借阅页面。为了避免重复输入id,使用php的session函数将检测时传递的id保存,向数据库表b_r插入数据时再用session获得该id,在文件最后清除这个id缓存。
如果借书的时候,在架书籍现存量为0,就会提示无法借阅,如果恰有一本,需要将书本的现存量减1,将是否可借调整为否
表b_r用于记录借阅情况,start_date用于记录借阅开始时间,默认为当下时间:CURRENT_TIMESTAMP
reader_id+book_id+start_date+keep_time
资格检查
没资格
有资格
现存量为0时进行借阅的提示,然后回到主页
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Check</title>
</head>
<body>
<form method="post" action="Check.php">
请输入您的读者号,确认您有资格借阅图书<br>
<input type="text" name="id">
<input type="submit" value="Check"><br>
<br>
<a href="homepage.html">或者直接回到主页</a>
</form>
</body>
</html>
Check.php
session_start();
$host = 'localhost';
$username = '';
$password = '';
$dbname = '';
$id = $_POST['id'];
$_SESSION['id']=$id;//保存读者id,供borrowbook.php使用
$url1="borrowbook.html";
$url2="homepage.html";
$mysql = new mysqli($host, $username, $password, $dbname);
if ($mysql->connect_errno) {
die('数据库连接失败:' . $mysql->connect_errno);
} else {
$mysql->set_charset('UTF-8'); // 设置数据库字符集
$sql = "SELECT available from reader where reader_id=$id"; // SQL 语句
$result = $mysql->query($sql);
$row = mysqli_fetch_row($result);
if ($row[0]==1)
{
$sql1="SELECT reader_name from reader where reader_id=$id";
$result1 = $mysql->query($sql1);
$row1 = mysqli_fetch_row($result1);
echo "";
echo "";
$mysql->close();
}
else {
echo "";
echo "";
$mysql->close();
}
}
borrowbook.html
<html>
<head>
<meta charset="utf-8">
<title>借书title>
<style type="text/css">
h1{
background-color: #678;
color:white;
text-align: center;
}
body{
height: 100%;
width: 100%;
border: none;
overflow-x: hidden;
}
div{
width:100%;
text-align: center;
}
style>
head>
<body>
<h1>借书h1>
<div>
<form method="post" action="borrowbook.php">
借阅书号:<input type="text" name="book_id"/>
借阅时间(天):
<input type="submit" value="借书"/>
form>
div>
body>
html>
borrowbook.php
session_start();
$host = 'localhost';
$username = '';
$password = '';
$dbname = '';
$id=$_SESSION['id'];//读取读者id
$book_id=$_POST['book_id'];//读取借阅书号
$keep=$_POST['keep_time'];
$url1="homepage.html";
$mysql = new mysqli($host, $username, $password, $dbname);
if ($mysql->connect_errno) {
die('数据库连接失败:' . $mysql->connect_errno);
} else{
$sql1="SELECT num from bookinfo where book_id=$book_id";
$result1=$mysql->query($sql1);
$row1=mysqli_fetch_row($result1);
if($row1[0]==0){
echo "";
echo "";
$mysql->close();
}
if($row1[0]==1){
$sql2="UPDATE bookinfo SET num=0,on_shelf='否' where book_id='$book_id'";
$sql3="INSERT INTO b_r(reader_id,book_id,keep_time) VALUES($id,$book_id,$keep)";
$result2=$mysql->query($sql2);
$result3=$mysql->query($sql3);
if($result2&&$result3){
echo "";
echo "";
$mysql->close();
}else{
echo "";
echo "";
$mysql->close();
}
}
if($row1[0]>1){
$sql4="INSERT INTO b_r(reader_id,book_id,keep_time) VALUES($id,$book_id,$keep)";
$sql5="UPDATE bookinfo SET num=num-1 where book_id='$book_id'";
$result4=$mysql->query($sql4);
$result5=$mysql->query($sql5);
if($result4&&$result5){
echo "";
echo "";
}
else{
echo "";
echo "";
}
}
}
$mysql->close();
unset($_SESSION['id']);
?>
淘汰书籍
bookinfo表中的book_id唯一确定一本书,根据id号进行淘汰,如果要淘汰的数量超过了现存量,现存量改为0,on_shelf改为否
<html>
<head>
<meta charset="utf-8">
<title>删除title>
<style>
h1{
background-color: #73EFE1;
color:red;
text-align: center;
}
style>
head>
<body>
<form onSubmit="return submit_sure()" method="post" action="delete.php" >
<h1>淘汰书籍h1>
<div align="center">
书号:<input type="text" name="id" size="20" ><br>
数量:<input type="number" min="0" size="10" name="num">
<br><br>
<input type="submit" value="确定">
div>
form>
body>
html>
<script language="javascript">
function submit_sure(){
var gnl=confirm("确定删除?");
if(gnl==true){
return true;
}else{
return false;
}
}
script>
delete.php
$host = 'localhost';
$username = '';
$password = '';
$dbname = '';
$id = $_POST['id'];
$num = $_POST['num'];
$mysql = new mysqli($host, $username, $password, $dbname);
if ($mysql->connect_errno) {
die('数据库连接失败:' . $mysql->connect_errno);
} else {
$sql0="SELECT * from bookinfo where book_id=$id";
$result0=$mysql->query($sql0);
$row = mysqli_fetch_row($result0);
if($row[4]<=$num){
$sql1 = "UPDATE bookinfo SET num=0,on_shelf='否' WHERE book_id=$id";
$result1=$mysql->query($sql1);
if ($result1) {
echo "";
} else {
echo "";
}
}else{
$sql2="UPDATE bookinfo SET num=num-$num WHERE book_id=$id";
$result2=$mysql->query($sql2);
if ($result2)
{
echo "";
} else
{
echo "";
}
}
$mysql->close();
}
?>
<a href="delete.html">继续</a> 或者 <a href="homepage.html">回到首页</a>
归还书籍
还书时需要根据book_id检测这本书有没有被人借阅,不同情况会进行提示。归还成功时需要将b_r表记录删除,同时若bookinfo表的on_shelf项为否,需改为是,然后将现存量加1
没有被借时提示
在借时提示
<html>
<head>
<meta charset="utf-8">
<title>还书title>
<style>
h1{
background-color: #678;
color:white;
text-align: center;
}
style>
head>
<body>
<h1>还书h1>
<div align="center">
<form method="post" action="return.php">
输入要归还的书号:<input type="text" name="id">
<input type="submit" value="确定">
form>
div>
body>
html>
return.php
$host = 'localhost';
$username = '';
$password = '';
$dbname = '';
$id = $_POST['id'];
$url1 = "homepage.html";
$mysql = new mysqli($host, $username, $password, $dbname);
if ($mysql->connect_errno) {
die('数据库连接失败:' . $mysql->connect_errno);
} else {
$sql1 = "SELECT book_id from b_r where book_id=$id";
$result1 = $mysql->query($sql1);
$row = mysqli_fetch_row($result1);
if ($result1 && $row[0] == $id) { //这本书的确在借
$sql2 = "DELETE from b_r where book_id=$id"; //清除b_r表记录
$result2 = $mysql->query($sql2);
$sql3 = "SELECT on_shelf,num from bookinfo where book_id=$id"; //更改bookinfo表信息
$result3 = $mysql->query($sql3);
$row1 = mysqli_fetch_row($result3); //row1[0]=on_shelf=是/否,row1[1]=num=0/...
if ($row1[0] == '否' || $row1[1] == 0) { //这本书归还之前已经没有了
$sql4 = "UPDATE bookinfo SET on_shelf='是',num=num+1 where book_id=$id";
$result4 = $mysql->query($sql4);
if ($result4) {
echo "";
echo "";
$mysql->close();
} else {
echo "";
echo "";
$mysql->close();
}
} else { //归还之前这本书还在架
$sql5 = "UPDATE bookinfo SET num=num+1 where book_id=$id";
$result5 = $mysql->query($sql5);
if ($result5) {
echo "";
echo "";
$mysql->close();
} else {
echo "";
echo "";
$mysql->close();
}
}
} else {
echo "";
echo "";
$mysql->close();
}
}
借阅情况
跟查看书籍相似,将b_r表数据以表格的形式显示
代码 Borrow.php
$host = 'localhost';
$username = '';
$password = '';
$dbname = '';
$mysql = new mysqli($host, $username, $password, $dbname);
if ($mysql->connect_errno) {
die('数据库连接失败:' . $mysql->connect_errno);
} else {
$sql = "select * from b_r";
$result = $mysql->query($sql);
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>All Information</title>
</head>
<body>
<table width="800px" border="1" style="border-collapse: collapse;">
<thead>
<th>读者编号</th>
<th>书号</th>
<th>借阅时间</th>
<th>借阅天数</th>
</thead>
while ($row = mysqli_fetch_row($result)) {
?>
<tr>
<td align="center"> echo $row[0]; ?></td>
<td align="center"> echo $row[1]; ?></td>
<td align="center"> echo $row[2]; ?></td>
<td align="center"> echo $row[3]; ?></td>
</tr>
}
?>
</table>
<br>
<a href="homepage.html">返回首页</a>
</body>
</html>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)