php学生管理系统整理
简介:
这是初学php的时候做的一个简单的增删改查,代码粗糙 , hxd们不要介意哈
1、首页
2.php文件
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<?php
include('3.php');
$query="SELECT * from tb_bookinfo ";
$result = mysqli_query($conn,$query);
echo '<table border="1" align="center">';
echo '<caption><h3>图书管理系统</h3></caption>';
echo '<tr>';
echo '<th align="center">ID</th>
<th align="center">书名</th>
<th align="center">作者</th>
<th align="center">价格</th>
<th align="center">类别</th>
<th colspan="2" align="center">操作</th>';
echo '</tr>';
while ($row = mysqli_fetch_array($result)){
echo '<tr>';
for ($i=0;$i<count($row)/2;$i++){
echo "<td>".$row[$i].' '."</td>";
}
echo '<td><a href="update.php?id='.$row[0].'&&bookName='.$row[1].'&&author='.$row[2].'&&price='.$row[3].'&&type='.$row[4].'">修改</a></td>>';
echo '<td><a href="delete.php?id='.$row[0].'">删除</a></td>>';
echo '</tr>';
}
echo '<tr align="right"><td colspan="6" ><a href="1.html"><input type="submit" value="查询"></a></td>
<td ><a href="insert.html"><input type="submit" value="填加"></a></td>
</tr>';
echo '<tr align="right"><td colspan="7">'.'共有记录:'.mysqli_num_rows($result).'条</td></tr>';
echo '</table>';
?>
</body>
</html>
3.php文件(数据库链接文件)
<?php
header("Content-Type:text/html;charset=utf-8");
$conn = mysqli_connect('localhost','root','root','book1') or exit('数据库连接失败!!');
首页效果图
查询部分
1.html文件
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>图书查询</title>
</head>
<body>
<form method="post" action="query.php">
<input type="text" name="bookName" placeholder="请输入书名">
<input type="submit" name="sub" value="查询">
</form>
</body>
</html>
query.php文件
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<?php
include('3.php');
$query="SELECT * from tb_bookinfo where bookname='".$_POST['bookName']."'";
$result = mysqli_query($conn,$query);
echo '<table border="1" align="center">';
echo '<caption><h3>图书管理系统</h3></caption>';
echo '<tr>';
echo '<th align="center">ID</th>
<th align="center">书名</th>
<th align="center">作者</th>
<th align="center">价格</th>
<th align="center">类别</th>';
echo '</tr>';
while ($row = mysqli_fetch_array($result)){
echo '<tr>';
for ($i=0;$i<count($row)/2;$i++){
echo "<td>".$row[$i].' '."</td>";
}
echo '</tr>';
}
echo '<tr align="right"><td colspan="3">'.'共有记录:'.mysqli_num_rows($result).'条</td></tr>';
echo '</table>';
?>
</body>
</html>
查询效果图

增加部分
add.php文件
<?php
header('Content-Type:text/html;charset=utf-8');
include ('3.php');
$bookName=$_POST['bookName'];
$author=$_POST['author'];
$price=$_POST['price'];
$type=$_POST['type'];
if($bookName&&$author&&$price&&$type){
$sql="insert into tb_bookinfo(bookname,author,price,type) values('".$bookName."','".$author."','".$price."','".$type."')";
$result=mysqli_query($conn,$sql);
if($result){
echo "添加成功,点击<a href='2.php'>这里</a>返回查询>";
}
else{
echo "添加失败,点击<a href='insert.html'>这里</a>重新添加>";
}
}else{
echo "输入的值不允许为空,点击<a href='javascript:οnclick=history.back()'>这里</a>返回>";
}
insert.html文件
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form action="add.php" method="post">
书名:<input type="text" name="bookName"><br>
作者:<input type="text" name="author"><br>
价格:<input type="text" name="price"><br>
类型:<input type="text" name="type"><br>
<input type="submit" value="添加">
</form>
</body>
</html>
添加效果图
修改部分
update.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form action="update_ok.php" method="post">
<input type="hidden" name="id" value="<?php
echo $_GET["id"]
?>"><br>
书名:<input type="text" name="bookName" value="<?php
echo $_GET["bookName"]
?>"><br>
作者:<input type="text" name="author" value="<?php
echo $_GET["author"]
?>">
<br>
价格:<input type="text" name="price" value="<?php
echo $_GET["price"]
?>"><br>
类型:<input type="text" name="type" value="<?php
echo $_GET["type"]
?>"><br>
<input type="submit" value="修改">
</form>
</body>
</html>
update_ok.php
<?php
header('Content-Type:text/html;charset=utf-8');
include('3.php');
$sql ="update tb_bookinfo set bookname='".$_POST['bookName']."',
author='".$_POST['author']."',
price='".$_POST['price']."',
type='".$_POST['type']."'
where id=
" .$_POST['id'];
$result = mysqli_query($conn, $sql);
if($result){
echo "修改成功,点击<a href='2.php'>这里</a>返回查询>";
}
else{
echo "修改失败";
}
修改效果图
删除部分
delete.php文件
<?php
header('Content-Type:text/html;charset=utf-8');
include('3.php');
$id=$_GET["id"];
$sql ="delete from tb_bookinfo where id=".$id;
$result = mysqli_query($conn, $sql);
if($result){
echo "删除成功,点击<a href='2.php'>这里</a>返回查看";
}
else{
echo "删除失败";
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!