65. 雇员管理系统(2)
2015-11-22 16:58
393 查看
1. 在登陆成功页面显示用户名:
2.分页技术
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> <?php if(!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>
相关文章推荐
- 序言
- Jade之条件语句
- Jade之注释
- 钢条切割问题
- Java读取文件MD5的两种方案
- 树形dp之删边
- Jade之Code
- 信息安全系统设计基础实验一—20135222胡御风20135215黄伟业
- P问题、NP问题、NPC问题以及NP-hard问题理解与区分
- 中间件简介
- 【C语言】【面试题】【笔试题】模拟实现strncpy
- maven学习2——pom.xml详解
- NYOJ-20 吝啬的国度
- ls ,tree,用法简单命令;alias别名用法(临时设置和永久设置)
- Jade之属性
- 第十一章 Intent原理与使用
- 【网络基础】计算机网络常考知识点整理
- iOS中的隐式动画
- 雨天+图书馆+一个人——忍不住记录一下最近
- 【NOIP2015】D2-T1跳石头,二分答案