本文实例为大家分享了php学生管理系统源码,供大家参考,具体内容如下
功能:
1.添加/删除/修改
2.数据存储.
界面分布:
index.php --->主界面
add.php --->stu添加
action ---> sql中add/del/update (处理html表单-->mysql的数据存储 && 页面跳转)
edit.php --->stu修改
menu.php -->首页
1. index.php
学生信息管理 <?php include ("menu.php"); ?>
浏览学生信息
ID | 姓名 | 性别 | 年龄 | 班级 | 操作 |
---|---|---|---|---|---|
{$row['id']} | "; echo "{$row['name']} | "; echo "{$row['sex']} | "; echo "{$row['age']} | "; echo "{$row['classid']} | "; echo "修改 删除 | "; echo "
2. add.php
学生管理系统 <?php include ('menu.php'); ?>
增加学生信息
3. action.php
<?php /** * Created by PhpStorm. * User: hyh * Date: 16-7-7 * Time: 下午9:37 */ //1. 链接数据库 try{ $pdo = new PDO("uri:mysqlPdo.ini","root","1"); }catch (PDOException $e) { // echo 'Connection failed: ' . $e->getMessage(); die('connection failed'.$e->getMessage()); } //2.action 的值做对操作 switch ($_GET['action']){ case 'add'://add $name = $_POST['name']; $sex = $_POST['sex']; $age = $_POST['age']; $classid = $_POST['classid']; $sql = "insert into stu (name, sex, age, classid) values ('{$name}', '{$sex}','{$age}','{$classid}')"; $rw = $pdo->exec($sql); if ($rw > 0){ echo ""; }else{ echo ""; } header('Location: index.php'); break; case 'del'://get $id = $_GET['id']; $sql = "delete from stu where id={$id}"; $rw = $pdo->exec($sql); if ($rw > 0){ echo ""; }else{ echo ""; } header('Location: index.php'); break; case 'edit'://post $id = $_POST['id']; $name = $_POST['name']; $age = $_POST['age']; $classid = $_POST['classid']; $sex = $_POST['sex']; // echo $id, $age, $age, $name; $sql = "update stu set name='{$name}', age={$age},sex='{$sex}',classid={$classid} where id={$id};"; // $sql = "update myapp.stu set name='jike',sex='女', age=24,classid=44 where id=17"; print $sql; $rw = $pdo->exec($sql); if ($rw > 0){ echo ""; }else{ echo ""; } header('Location: index.php'); break; default: header('Location: index.php'); break; }
4.edit.php
<?php ?>学生管理系统 <?php include ('menu.php'); //1. 链接数据库 try{ $pdo = new PDO("uri:mysqlPdo.ini","root","1"); }catch (PDOException $e) { die('connection failed'.$e->getMessage()); } //2.执行sql $sql_select = "select * from stu where id={$_GET['id']}"; $stmt = $pdo->query($sql_select); if ($stmt->rowCount() >0) { $stu = $stmt->fetch(PDO::FETCH_ASSOC); // 解析数据 }else{ die("no have this id:{$_GET['id']}"); } ?>
修改学生信息
5. menu.php
学生管理系统
浏览学生 添加学生
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持全福编程网。