版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、本文实例为大家分享了php学生管理系统源码,供大家参考,具体内容如下功能:&n bsp;1添加/删除/修改2数据存储界面分布:index.php ->主界面add.php ->stu 添加页面跳action -> sql 中 add/del/update (处理 html 表单->mysql 的数据存储 & 转)edit.php ->stu 修改menu.php ->首页1. in dex.php& lt;!DOCTYPE html >& lt;html la ng=e n>& t;head >&n bsp; & lt;meta chars
2、et=UTF-8> &t;title>学生信息管理 </title>&n bsp; & t;script>&n bsp; &n bsp; fun cti on doDel(id) if(confirm( 确认删除?)&n bsp; &n bsp; &n bsp; &n bsp; win dow .lo cati on=act ion. php?act ion=del& amp;id=+id;&n bsp; &n bsp; &n bsp; &n bsp; &n bsp; &n bsp; & t;/script &
3、gt;</head >& t;body >& lt;ce nter>&n bsp; & t;?php&n bsp; in clude (me nu .php);&n bsp; ?> &It;h3>浏览学生信息 &It;/h3>&n bsp; & lt;table width=500 border=1>&n bsp; &n bsp; & lt;tr>&n bsp; &n bsp; &n bsp; <th >ID & lt;/th>姓名& lt;/th > 性别& lt;/th > 年龄& lt;/th
4、 > 班级& t;/th > 操作& lt;/th >&n bsp; &n bsp; &n bsp; & lt;th > &n bsp; &n bsp; &n bsp; & lt;th > &n bsp; &n bsp; &n bsp; & lt;th > &n bsp; &n bsp; &n bsp; & lt;th > &n bsp; &n bsp; &n bsp; & lt;th > &n bsp; &n bsp; & t;/tr>&n bsp; &n bsp; & t;?php/ &n bsp; &n bsp;1.链接数据库&n b
5、sp; &n bsp; try&n bsp; &n bsp; &n bsp; $pdo = new PDO(uri:mysqlPdo.i ni,root,1);&n bsp; &n bsp; catch (PDOException $e) &n bsp; &n bsp; &n bsp; die(c onnection failed.$e->getMessage();&n bsp; &n bsp; 2.执行 sql&n bsp; &n bsp; $sql_select = select * from stu; 3.data 解析&n b
6、sp; &n bsp; foreach ( $pdo->query($sql_select) as $row) &n bsp; &n bsp; &n bsp; echo <tr>&n bsp; &n bsp; &n bsp; echo <th >$rowid </th >&n bsp; &n bsp; &n bsp; echo <th >$row name</th >&n bsp; &n bsp; &n bsp; echo <th >$rowsex </th>&n bsp; &n bsp; &n bsp;
7、 echo <th >$rowage </th>&n bsp; &n bsp; &n bsp; echo <th >$rowclassid</th >&n bsp; &n bsp; &n bsp; echo <td > &t;a href=edit.php?id=$rowid>修改</a>&n bsp; &n bsp; &n bsp; &n bsp;&n bsp;<a href=javascript:void(0);on click=doDel
8、($rowid) >删除 </a>&n bsp; &n bsp; &n bsp; &n bsp; & lt;/td >&n bsp; &n bsp; &n bsp; echo </tr>&n bsp; &n bsp; &n bsp; &n bsp; ?>&n bsp; & t;/table >& lt;/ce nter>& t;/body >& lt;/html>2. add.php&n bsp;& lt;!DOCTYPE html >& lt;html la ng=e n>& lt;head >&n bsp;
9、 & lt;meta charset=UTF-8> &t;title>学生管理系统 </title></head >& lt;body >& lt;ce nter>&n bsp; <?php in clude (me nu .php); ?& gt; &It;h3>增加学生信息 &It;/h3>&n bsp; <form action=acti on .php?act ion=add method=post>&n bsp; &n bsp; & lt;table>&n bsp; &n bs
10、p; &n bsp; & lt;tr>&n bsp; &n bsp; &n bsp; &n bsp; & lt;td >姓名& lt;/td >&n bsp;&n bsp;&n bsp;&n bsp;& lt;td >< in puttype=text name= name> </td >&n bsp; &n bsp; &n bsp; & t;/tr>&n bsp; &n bsp; &n bsp; & lt;tr>&n bsp; &n bsp; &n bsp; &n bsp; & lt;td > 年龄& lt;/td >&
11、n bsp; &n bsp; &n bsp; &n bsp; & lt;td >< in put type=text name=age > ;</td >&n bsp; &n bsp; &n bsp; & t;/tr>&n bsp; &n bsp; &n bsp; & lt;tr>&n bsp; &n bsp; &n bsp; &n bsp; & lt;td >性别& lt;/td > <td><inputtype=radioname=sex value=男>男&t;/td
12、> <td><inputtype=radioname=sex value=女>女&t;/td>&n bsp; &n bsp; &n bsp; & t;/tr>&n bsp; &n bsp; &n bsp; & lt;tr>&n bsp; &n bsp; &n bsp; &n bsp; & lt;td >班级& lt;/td >&n bsp;&n bsp;&n bsp; &n bsp;& lt;td >< in puttype=textname=classid></t
13、d >&n bsp; &n bsp; &n bsp; & t;/tr>&n bsp; &n bsp; &n bsp; & lt;tr>& t;!- &n bsp; &n bsp; &n bsp; &n bsp ;& lt;td > & lt;/td >-> <td><a href=index.php>返回 </td> <td><inputtype=submit value=添加></td &
14、gt; <td><inputtype=reset value=重置></td >&n bsp; &n bsp; &n bsp; & t;/tr>&n bsp; &n bsp; & t;/table > ;&n bsp;&n bsp; </form >& lt;/ce nter>& t;/body >& lt;/html>3. action, php&n bsp;& t;?php/*&n bsp;* Created by PhpStorm.&n bsp;* User: hy
15、h&n bsp;* Date: 16-7-7 * Time:下午 9:37&n bsp;*/1.链接数据库try&n bsp; $pdo = new PDO(uri:mysqlPdo.i ni,root,1);catch (PDOException $e) / &n bsp; &n bsp; &n bsp;echo Connection failed: . $e->getMessage();&n bsp; die(c onnection failed.$e->getMessage();2.action的值做对操作switch ($_GETactio n)&n bsp; c
16、ase add:/add&n bsp;&n bsp; &n bsp; $n ame = $_POST name;&n bsp; &n bsp; $sex = $_POSTsex;&n bsp; &n bsp; $age = $_POSTage;&n bsp; &n bsp; $classid = $_POSTclassid;&n bsp; &n bsp; &n bsp;&n bsp; $sql = insert into stu (name, sex, age, classid) values ($name.$sex,$age,$classid);&n bsp; &n
17、 bsp; $rw = $pdo->exec($sql);&n bsp;&n bsp; &n bsp; if ($rw & gt; 0) echo <script>alter(添加成功);</script>&n bsp; &n bsp; else echo <script>alter(添加失败);</script>&n bsp; &n bsp; &n bsp; &n bsp; header(Locati on: in dex.php);&n bsp; &n bs
18、p; break ;&n bsp;&n bsp; case del:/get&n bsp; &n bsp; $id = $_GETid;&n bsp; &n bsp; $sql = delete from stu where id=$id;&n bsp; &n bsp; $rw = $pdo->exec($sql);&n bsp; &n bsp; if ($rw > 0) echo <script>alter(删除成功);</script>&n bsp; &n bsp; else
19、 echo <script>alter(删除失败);</script>&n bsp; &n bsp; &n bsp; &n bsp; header(Locati on: in dex.php);&n bsp; &n bsp; break;&n bsp; case edit:/post&n bsp; &n bsp; $id = $_POSTid;&n bsp; &n bsp; $n ame = $_POST name;&n bsp;&n bsp; &n bsp; $age = $_POSTage;&n bsp; &n bsp; $classid = $_POSTclass
20、id;&n bsp; &n bsp; $sex = $_POSTsex;&n bsp; &n bsp; &n bsp;&n bsp;/ &n bsp; &n bsp;echo $id, $age, $age, $n ame;&n bsp;&n bsp; $sql = update stu setn ame=$ 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;&
21、n bsp; &n bsp; print $sql;&n bsp; &n bsp; $rw = $pdo->exec($sql);&n bsp; &n bsp; if ($rw > 0) echo <script>alter(更新成功);</script>&n bsp; &n bsp; else echo <script>alter(更新失败);</script>&n bsp; &n bsp; &n bsp; &n bsp; header(Locati o
22、n: in dex.php);&n bsp; &n bsp; break ;&n bsp;&n bsp; default:&n bsp; &n bsp; header(Locati on: in dex.php);&n bsp; &n bsp; break;4. edit.php& lt;!DOCTYPE html >& lt;html la ng=e n>& lt;head >&n bsp; & lt;meta charset=UTF-8> &t;title>学生管理系统 </title></head >& lt;body &
23、gt;& lt;ce nter>&n bsp; <?php in clude (me nu .php); /1.链接数据库&n bsp; try&n bsp; &n bsp; $pdo = new PDO(uri:mysqlPdo.i ni,root,1);&n bsp; catch (PDOException $e) &n bsp; &n bsp; die(c onnection failed.$e->getMessage();&n bsp; /2.执行 sql&n bsp; $sql_select = select * from stu wher
24、e id=$_GETid;&n bsp; $stmt = $pdo->query($sql_select);&n bsp; if ($stmt->rowCou nt() >0) &n bsp; &n bsp; $stu = $stmt->fetch(PDO:FETCH_ASSOC); /解析数据&n bsp; else&n bsp; &n bsp; die( no have this id:$_GETid);&n bsp; &n bsp; ?> &It;h3>修改学生信息 &It;/h3>&n bsp; <form action=ac
25、ti on .php?act ion=edit method=post >echo&n bsp;&n bsp;<i nput type=hidde nn ame=idvalue=<?php$stuid;?>>&n bsp; &n bsp; & lt;table>&n bsp; &n bsp; &n bsp; & lt;tr>&n bsp; &n bsp; &n bsp; &n bsp; & lt;td >姓名& lt;/td >&n bsp;&n bsp;&n bsp;&n bsp;<td > ;& lt;i nputtype=t
26、extn ame=n amevalue=<?php echo $stu name;? >></td >&n bsp; &n bsp; &n bsp; & t;/tr>&n bsp; &n bsp; &n bsp; & lt;tr>&n bsp; &n bsp; &n bsp; &n bsp; & lt;td >年龄& lt;/td >&n bsp; &n bsp;&n bsp;&n bsp;<td > ;<i nputtype=text n ame=agevalue=<?php echo $stuage;? >&
27、gt;</td >&n bsp; &n bsp; &n bsp; & t;/tr>&n bsp; &n bsp; &n bsp; & lt;tr>&n bsp; &n bsp; &n bsp; &n bsp; & lt;td >性别& lt;/td >&n bsp; &n bsp; &n bsp; &n bsp; & lt;td > <input type=radio name=sex value=男 <?php echo ($stusex=男)? checked:;?&g
28、t; >男&n bsp; &n bsp; &n bsp; &n bsp; </td >&n bsp; &n bsp; &n bsp; &n bsp; & lt;td > <input type=radio name=sex value=女 <?php echo ($stusex=女)? checked:;?> >女&n bsp; &n bsp; &n bsp; &n bsp; </td >&n bsp; &n bsp; &n bsp; & t;/tr>&n bsp; &
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2024年室内装修项目标准协议模板版B版
- 2024全年洗车服务加盟协议版A版
- 2024年全职雇佣合同2篇
- 2024年城市供水管道建设合同
- 2024年度影视制作合同标的剧本创作和拍摄要求
- 2024年度人力资源部门总监聘任合同
- 2024年度青岛社区服务居间合同2篇
- 2024年新款小汽车短期租赁服务合同版
- 2024年农业开垦与土地利用合同3篇
- 2024年智能工厂生产线升级改造合作协议
- 关于管理的四个职能
- 【教学创新大赛】《管理学》教学创新成果报告
- 国家开放大学《Python语言基础》形考任务3参考答案
- 事业单位面试题-人际关系类
- 部编版小学语文一年级上册八单元整体解读
- 健康指南肾囊肿患者应该如何进行有效的治疗
- 生活区公共服务设施布局规划优化
- DB21-T 2780.1-2017辽东落叶松二元立木材积表 第1 部分 日本落叶松
- 项目亏损分析报告
- 地源热泵施工流程课件
- 改善与客户需求的沟通技巧
评论
0/150
提交评论