65. 雇员管理系统(2)
来源:互联网 发布:高清矩阵 编辑:程序博客网 时间:2024/04/29 12:13
1. 在登陆成功页面显示用户名:
login.php<html><head> <meta http-equiv="content-type" content="text/html;charset=utf-8"/></head><body><h1>管理员登陆系统</h1><form action="loginProcess.php" method="post"> <table> <tr> <td>用户id</td><td><input type="text" name="id"/></td> </tr> <tr> <td>密码</td><td><input type="password" name="password"/></td> </tr> <tr> <td><input type="submit" value="用户登陆"/></td> <td><input type="reset" value="重新填写"/></td> </tr> </table></form><?phpif(!empty($_GET['errno'])){ //接收errno $errno = $_GET['errno']; if($errno == 1){ echo "<br/><font color='red'>你的用户名或者密码错误</font>"; }}?></body></html>
loginProcess.php<?php$id = $_POST['id'];$password = $_POST['password'];//到数据库去验证//1.得到连接$link = mysql_connect('localhost','root','123456');if(!$link){ die('连接失败' . mysql_error());}//2.设置访问数据库的编码形式mysql_query('set names utf8',$link) or die('set names error' . mysql_error());//3.选择数据库mysql_select_db('test',$link) or die(mysql_error());//4.发送sql语句,验证//防止sql注入攻击//改变验证逻辑//$sql = "select * from admin where id='{$id}' and password='{$password}'";$sql = "select password,name from admin where id='{$id}' and password='{$password}'";//1.通过输入的id来获取数据库中的密码,再和输入的密码进行比对$res = mysql_query($sql,$link);if($row = mysql_fetch_assoc($res)){ //查询到了 //2.取出数据库的密码 if($row['password'] == $password){ //说明合法 //取出用户的名字 $name = $row['name']; header("Location:empManage.php?name=$name"); exit(); }} header('Location:login.php?errno=1'); exit();//关闭资源mysql_free_result($res);mysql_close($link);/*if($id == '100' && $password =='123'){ //合法,跳转到empManage.php header('Location:empManage.php'); //跳转后要退出,最好退出,退出进程,一个请求对应一个进程 exit();}else{ //非法,跳转回去 header('Location:login.php?errno=1');//带点信息给login.php exit();}*/
empManage.php<html><head> <meta http-equiv="content-type" content="text/html;charset=utf-8"/></head><body><?php //显示出用户名 echo "欢迎 --- " . $_GET['name'] ."--- 登陆成功";?><h1>主页面</h1><a href="empList.php">管理用户</a><br/><a href="">添加用户</a><br/><a href="">查询用户</a><br/><a href="">退出系统</a><br/></body></html><?php header('Content-Type:text/html;charset=utf-8'); echo "登陆成功<br/>"; echo "<br/><a href='login.php'>返回重新登陆</a>";?>
empList.php<html><head> <meta http-equiv="content-type" content="text/html;charset=utf-8"/></head><body><?php //显示所有用户的信息(表格) //查询数据库 $mysqli = new MySQLi('localhost','root','123456','test'); if($mysqli->connect_error){ die('connect error' . $mysqli->connect_error); } $mysqli->set_charset('utf8') or die($mysqli->error); $sql = "select * from emp;"; $res = $mysqli->query($sql); if(!$res){ die($mysqli->error); } while($row = $res->fetch_row()){ $rows[] = $row; } $res->free(); $mysqli->close();?><h1>雇员信息列表</h1><table border="1" cellpadding="0" cellspacing="0" width="80%"> <tr> <th>id</th> <th>name</th> <th>grade</th> <th>email</th> <th>salary</th> <th>操作</th> </tr> <?php foreach($rows as $row):?> <tr> <td><?php echo $row[0];?></td> <td><?php echo $row[1];?></td> <td><?php echo $row[2];?></td> <td><?php echo $row[3];?></td> <td><?php echo $row[4];?></td> <td><a href="">删除用户</a>|<a href="">修改用户</a></td> </tr> <?php endforeach;?></table></body></html>
2.分页技术
在分页中有几个变量是必须的:$pageNow :显示第几页,用户输入$pageCount:共有几页($rowCount/$pageSize 计算出来)$rowCount:共有多少记录(这个从数据库中获取)$pageSize:每页显示几条记录(程序员指定)例子:$pageNow = 1;$rowCount = 1;$pageSize = 1$pageCount = ceil($rowCount/$pageSize);
<html><head> <meta http-equiv="content-type" content="text/html;charset=utf-8"/></head><body><?php //显示所有用户的信息(表格) //查询数据库 $mysqli = new MySQLi('localhost','root','123456','test'); if($mysqli->connect_error){ die('connect error' . $mysqli->connect_error); } $mysqli->set_charset('utf8') or die($mysqli->error); //分页显示 $pageSize = 2;//默认每页显示几行记录 $rowCount = 0;// 这个变量要从数据库取 $pageNow = 1;//显示第几页,这是一个变化量(用户指定)//这里我们需要根据用户的点击来修改 $pageNow//这里我们需要判断是否有这个pageNow法师,有就使用,没有则使用默认值--显示第一页if(!empty($_GET['pageNow'])){ $pageNow = $_GET['pageNow'];} $pageCount = 0;//表示一共有几页,是计算出来的 $sql = "select count(id) from emp;"; $res1 = $mysqli->query($sql); //取出行数 if($row = $res1->fetch_row()){ $rowCount = $row[0]; } //计算共有多少页 $pageCount = ceil($rowCount/$pageSize); $sql = "select * from emp limit " . ($pageNow - 1)*$pageSize . ",$pageSize"; //var_dump($sql);die(); //$sql = "select * from emp limit 0,2;"; $res2 = $mysqli->query($sql); if(!$res2){ die($mysqli->error); } while($row = $res2->fetch_row()){ $rows[] = $row; } $res2->free(); $mysqli->close();?><h1>雇员信息列表</h1><table border="1" cellpadding="0" cellspacing="0" width="80%"> <tr> <th>id</th> <th>name</th> <th>grade</th> <th>email</th> <th>salary</th> <th>操作</th> </tr> <?php foreach($rows as $row):?> <tr> <td><?php echo $row[0];?></td> <td><?php echo $row[1];?></td> <td><?php echo $row[2];?></td> <td><?php echo $row[3];?></td> <td><?php echo $row[4];?></td> <td><a href="">删除用户</a>|<a href="">修改用户</a></td> </tr> <?php endforeach;?></table><?php //打印出页码的超链接 for($i=1;$i<=$pageCount;$i++){ echo "<a href='empList.php?pageNow=$i'>$i</a> "; }?></body></html>
0 0
- 65. 雇员管理系统(2)
- 雇员管理系统ssh之准备2
- 公司雇员管理系统
- 64. 雇员管理系统
- 雇员管理系统
- 简单的雇员管理系统
- 11、完成雇员管理系统
- 项目开发:雇员管理系统
- 雇员管理系统_java_控制台
- 雇员系统2
- PHP自学之路---雇员管理系统(2)
- 04-php雇员管理系统-实现显示雇员信息列表
- Spring实战-雇员薪资管理系统
- EMS-Demo 雇员管理系统演示
- 雇员管理系统ssh之准备1
- 雇员管理系统-SSH版(一)
- 雇员管理系统-SSH版(二)
- 雇员管理系统-SSH版(三)
- Java读取文件MD5的两种方案
- NYOJ-20 吝啬的国度
- P问题、NP问题、NPC问题以及NP-hard问题理解与区分
- 单片机学习之硬件基础知识学习
- 树形dp之删边
- 65. 雇员管理系统(2)
- 序言
- 我的sublime python环境配置
- maven学习2——pom.xml
- [LeetCode]Permutations II
- 学习算法,编程之路
- 编写一个将输入复制到输出的程序 ,并将其中连续的多个空格用一个空格代替 //学习笔记 编写一个将输入复制到输出的程序 ,并将其中连续的多个空格用一个空格代替 运行环境vs2015 #includ
- Linux系统启动流程
- NYOJ-755山谷【模拟】