PHP+MYSQL学生信息管理系统实现增删改查(超简单版)

首先导入数据库

php源码地址

https://download.csdn.net/download/weixin_45783299/19403983?spm=1001.2014.3001.5503

-- MariaDB dump 10.17  Distrib 10.4.13-MariaDB, for Win64 (AMD64)
--
-- Host: localhost    Database: stu_result
-- ------------------------------------------------------
-- Server version	10.4.13-MariaDB

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--
-- Current Database: `stu_result`
--

CREATE DATABASE /*!32312 IF NOT EXISTS*/ `stu_result` /*!40100 DEFAULT CHARACTER SET utf8mb4 */;

USE `stu_result`;

--
-- Table structure for table `result`
--

DROP TABLE IF EXISTS `result`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `result` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(64) NOT NULL,
  `age` int(11) NOT NULL,
  `result` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `result`
--

LOCK TABLES `result` WRITE;
/*!40000 ALTER TABLE `result` DISABLE KEYS */;
INSERT INTO `result` VALUES (1,'李伟',19,90),(2,'王明',18,86),(3,'李琴',21,80),(4,'陈莉',20,100),(5,'张阳',20,85),(6,'王云',21,90),(7,'赵伟',18,78),(8,'张强',19,90),(9,'王力',19,77),(10,'刘林',20,95);
/*!40000 ALTER TABLE `result` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `user`
--

DROP TABLE IF EXISTS `user`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `user` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `account` varchar(32) NOT NULL,
  `password` varchar(32) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `user`
--

LOCK TABLES `user` WRITE;
/*!40000 ALTER TABLE `user` DISABLE KEYS */;
INSERT INTO `user` VALUES (1,'user','user'),(2,'admin','admin'),(3,'111','111');
/*!40000 ALTER TABLE `user` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

-- Dump completed on 2021-05-25 10:25:21

再创建几个php文件

在这里插入图片描述

然后代码代码来了 按顺序创建

conn.php

<?php
$servername="localhost:3306";  
$username="root";
$password="123456";
$dbname="stu_result";
//创建连接
$conn=new mysqli($servername,$username,$password,$dbname);
@mysqli_set_charset($conn,"utf8");
//检测连接
if($conn->connect_error){
die("连接失败:".$conn->connect_error);
}
?>

index.php

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>成绩列表</title>
		<link rel="stylesheet" type="text/css" href="css/style.css">
	</head>
<body>
<h1>学生成绩管理系统</h1>
<table>
<?php
	session_start();
	if(!$_SESSION['user.account']){
	
		//print_r($_SESSION['user.account']);
		header('location:login.php');
	}
	
include("conn.php");
$sql="select * from result";
$result=$conn->query($sql);
if($result->num_rows>0){
while($row=$result->fetch_assoc()){
?>
<tr>
	<td><?php echo $row["id"]; ?></td>
	<td><?php echo $row["name"]; ?></td>
	<td><?php echo $row["age"]; ?></td>
	<td><?php echo $row["result"]; ?></td>
	<td>
	<button onclick="toUpdate(this)">修改</button>
	<button onclick="remove(this)">删除</button>
	</td>
</tr>
<?php
}
}
?>
	<tr>
		<td colspan="5"><a href="insert.php"><button>添加
		</button></a></td>
	</tr>
	</table>
</body>
</html>
<script type="text/javascript">
function remove(ele){
var conf=confirm('确定要删除吗?');
if(conf==true){
let id=ele.parentElement.parentElement.children[0].innerText;
window.location.href="remove_server.php?id="+id;
}
}
function toUpdate(ele){
 let id=ele.parentElement.parentElement.children[0].innerText;
 window.location.href="update.php?id="+id;
}
</script>

login.php

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>用户登录</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<h1>学生成绩管理系统</h1>
<table>
    <form action="./user_server.php" method="post">
       
        <tr>
            <td>用户名:</td>
            <td><input type="text" name="account"/></td>
        </tr>
        <tr>
            <td>密码:</td>
            <td><input type="password" name="password" /></td>
        </tr>
        <tr>
            <td><button type="submit">登录</button></td>  
        </tr>
      
    </form>
        <tr>
            <td><button onclick="registered(this)">注册</button></td>
        </tr>
    </table>
</body>
</html>
<?php
 session_start();
 $_SESSION['user.account']='';
?>

<script type="text/javascript">
function registered(ele){
 let id=ele.parentElement.parentElement.children[0].innerText;
 window.location.href="registered.php";
}
</script>


user_server.php

<!DOCTYPE html>
<html lang="en">
<head>
    <title></title>
</head>
<body>
<a href="login.php">返回</a>
</body>
</html>
<?php
	include'conn.php';
    session_start();
    $_SESSION['user.account']='';
    if($conn){
       //echo"连接成功";
      $result=mysqli_query($conn,"select *from user;");
        if(isset($_POST['account'])&&isset($_POST['password'])){
            $user=$_POST['account'];
            $pass=$_POST['password'];
            $bool=false;
        while($r=mysqli_fetch_object($result)){
            if( $r->account==$user&&$r->password==$pass){
                $_SESSION['user.account']=1;
                $bool=true;
                header('Location:index.php');
                }
            }
            if(!$bool){
            echo'<script type="text/javascript">
                window.alert("账号或密码不一致");
            </script>';
         }
        }
    }
   

registered.php

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="style.css">
    <title>注册</title>
</head>
<body>
    <table border="0">
        <form action="registered.php" method="post">   
            <h1>注册</h1>
               账号:<input type="text" name="user"></br>
                密码:<input type="password" name="pass"></br>
               <input type="submit" value="注册"></br>    
        </form>
        </table>
</body>
</html>

<?php
include 'conn.php';
if($conn){
    if(isset($_POST['user'])&&isset($_POST['pass'])){
        $user=$_POST['user'];
        $pass=$_POST['pass'];
        $sql="insert into user (account,password) values('$user','$pass');";
   if(mysqli_query($conn,$sql)){
      // echo "<script>window.alert('注册成功');<script>";
       header('location:login.php');
   }else{
    echo "Error: " . $sql . "<br>" . mysqli_error($conn);
   }
   
        
    }
}

insert.php

<body>
<h1>添加学生</h1>
<form action="insert.php" method="post">
<table>
<tr>
<td>姓名:</td>
<td><input type="text" name="name" require/></td>
</tr>
<tr>
<td>年龄:</td>
<td><input type="number" name="age" require/></td>
</tr>
<tr>
<td>成绩:</td>
<td><input type="text" name="score" require/></td>
</tr>
<tr>
<td><button type="submit" name="submit">添加</button></td>
</tr>
</table>
</form>
</body>
</html>

<?php
require('conn.php');
session_start();
if(!$_SESSION['user.account']){
	//print_r($_SESSION['user.account']);
	header('location:login.php');
}
@$name=$_POST['name'];
@$age=$_POST['age'];
@$score=$_POST['score'];

$sql="insert into result (name,age,result) values('$name','$age','$score') ";
//echo $sql;
if(isset($_POST["submit"])):
$r=mysqli_query($conn,$sql);
if($r){
    header("location:index.php");
}else{
    echo "添加失败";
}
endif;

update.php

<body>
<h1>修改学生</h1>
<form action="update.php" method="post">
<table>
<tr>
<td>姓名:</td>
<td><input type="text" name="name" require/></td>
</tr>
<tr>
<td>年龄:</td>
<td><input type="number" name="age" require/></td>
</tr>
<tr>
<td>成绩:</td>
<td><input type="text" name="score" require/></td>
</tr>
<tr>
<td><button type="submit">修改</button></td>
</tr>
</table>
</form>
</body>
</html>

<?php
	include'conn.php';
	session_start();

	if(!$_SESSION['user.account']){

		//print_r($_SESSION['user.account']);
		header('location:login.php');
	}

	@$id=$_SESSION['user.id'];
	
	@$name=$_POST['name'];
	@$age=$_POST['age'];
	@$score=$_POST['score'];
	$sql="update result set name='$name',result='$score',age=$age where id='$id'";	
	//echo $sql;
	$r=mysqli_query($conn,$sql);
		if($r){
		header("location:index.php");	
		}	

@$_SESSION['user.id']=$_GET['id'];
	
?>

remove_server.php

<?php
require'conn.php';

if(!$_SESSION['user.account']){
	//print_r($_SESSION['user.account']);
	header('location:login.php');
}

session_start();
//$id=$_SESSION['user.id'];
$id=$_GET['id'];
$sql="delete from result where id=$id";
$r=mysqli_query($conn,$sql);
if($r){
    header("location:index.php");
}
  • 12
    点赞
  • 199
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 20
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 20
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

叶功隽

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值