规划图:
<a href="http://guojiping.blog.51cto.com/attachment/201401/12/5635432_1389498471zcpl.png" target="_blank"></a>
一、数据库的设计:
数据库的创建: create database empmanage;
管理员表Admin
create table admin(
Adm_id int primary key,
Adm_name varchar(32) not null,
Adm_password varchar(128) not null );
雇员表:emp
create table emp(
Emp_id int primary key auto_increment,
Emp_name varchar(64) not null,
Emp_grade tinyint,
Emp_email varchar(64) not null,
Emp_salary float
);
添加点数据表里:
insert into emp (Emp_name,Emp_grade,Emp_email,Emp_salary) values ('jiping',1,'[email protected]',3000);
添加多条,作为后面的分页使用!
insert into admin values(100,'admin',md5('admin'));
<a href="http://guojiping.blog.51cto.com/attachment/201401/12/5635432_1389498472Lu0K.png" target="_blank"></a>
二、登陆的实现:
第1种方法:简单的实现,不到数据库验证!
第一个界面:login.php
<html>
<head>
<metahttp-equiv="content-type"content="text/html;charset=utf-8">
</head>
<h1>管理员登陆系统</h1>
<formaction="loginprocess.php"method="post">
<table>
<tr><td>用户id</td><td><inputtype="text"name="id"/></td></tr>
<tr><td>密&nbsp;码</td><td><inputtype="password"name="password"/></td></tr>
<tr>
<td><inputtype="submit"value="用户登录"/></td>
<td><inputtype="reset"value="重新填写"/></td>
</tr>
</table>
</form>
<?php
if(!empty($_GET['errno'])){
$errno=$_GET['errno'];
if($errno=='1'){
echo "<br/><font color='red' size='3'>你的用户名和密码有误";
}
?>
</html>
第二个界面:loginprocess.php
//接收用户的数据
$id=$_POST['id'];
$password=$_POST['password'];
if($id=="100" && $password=="123"){
//合法:跳转到empManage.php
header("Location: empManage.php");
exit();
}else {
header("Location: login.php?errno=1");
第三个界面:empManage.php
echo "登录成功";
测试结果:
登陆成功的话:
<a href="http://guojiping.blog.51cto.com/attachment/201401/12/5635432_1389498473MqIV.png" target="_blank"></a>
<a href="http://guojiping.blog.51cto.com/attachment/201401/12/5635432_1389498474Fc3u.png" target="_blank"></a>
故意输错,在下面出现提示!
<a href="http://guojiping.blog.51cto.com/attachment/201401/12/5635432_1389498475dpP3.png" target="_blank"></a>
第2种方法:到数据库验证:
<a href="http://guojiping.blog.51cto.com/attachment/201401/12/5635432_1389498476geYf.png" target="_blank"></a>
第2种方法的实现:loginprocess.php
//2.到数据库进行验证
$conn=mysql_connect("localhost","root","123456");
if(!$conn)
{
die("连接失败".mysql_errno());
mysql_query("set names utf8",$conn) or die(mysql_errno());
mysql_select_db("empmanage",$conn) ordie(mysql_errno());
$sql="select Adm_password from admin where Adm_id=$id";
$res=mysql_query($sql,$conn);
if($row=mysql_fetch_assoc($res))
//查询到id,下面要比对密码
if($row['Adm_password']==md5($password))
//关闭资源
mysql_free_result($res);
mysql_close($conn);
先看下数据库中的管理员表:
<a href="http://guojiping.blog.51cto.com/attachment/201401/12/5635432_1389498477noHB.png" target="_blank"></a>
<a href="http://guojiping.blog.51cto.com/attachment/201401/12/5635432_1389498478agbZ.png" target="_blank"></a>
<a href="http://guojiping.blog.51cto.com/attachment/201401/12/5635432_1389498479tZ9L.png" target="_blank"></a>
三、如何出现,欢迎某个用户登录的界面!
实现方法,用Get 方式传递
(注意:数据库的选取字段)loginprocess.php
$sql="select Adm_password,Adm_name from admin where Adm_id=$id";
{ //查询到id,下面要比对密码
{$name=$row['Adm_name'];
header("Location: empManage.php?name=$name");
empManage.php
echo "欢迎".$_GET['name']."登录成功";
<a href="http://guojiping.blog.51cto.com/attachment/201401/12/5635432_1389498480cKdY.png" target="_blank"></a>
四、现在实现:整体设计
<a href="http://guojiping.blog.51cto.com/attachment/201401/12/5635432_1389498482Hbqo.png" target="_blank"></a>
这里的empMain.php由 empManage.php来代替
echo "<br/><a href='login.php'>返回登陆界面";
<h1>主界面</h1>
<ahref='emplist.php'>管理用户</a><br/>
<ahref='#'>添加用户</a><br/>
<ahref='#'>查询用户</a><br/>
<ahref='#'>退出系统</a><br/>
<a href="http://guojiping.blog.51cto.com/attachment/201401/12/5635432_1389498483pHOf.png" target="_blank"></a>
<a href="http://guojiping.blog.51cto.com/attachment/201401/12/5635432_13894984840pmn.png" target="_blank"></a>
<a href="http://guojiping.blog.51cto.com/attachment/201401/12/5635432_1389498485wPxv.png" target="_blank"></a>
<a href="http://guojiping.blog.51cto.com/attachment/201401/12/5635432_1389498486UTll.png" target="_blank"></a>
<a href="http://guojiping.blog.51cto.com/attachment/201401/12/5635432_138949848792xu.png" target="_blank"></a>
<a href="http://guojiping.blog.51cto.com/attachment/201401/12/5635432_1389498489j2LF.png" target="_blank"></a>
<a href="http://guojiping.blog.51cto.com/attachment/201401/12/5635432_1389498492Yoas.png" target="_blank"></a>
Emplist.php 页面代码
<metahttp-equiv="content-type"content="text/html charset=utf-8">
<title>雇员信息列表</title>
//显示所有用户的信息(表格)查询数据,在数据库
$pageSize=3;
$rowCount=0;
$pageNow=1;//如果没有传送这个参数的话,默认值为1
if(!empty($_GET['pageNow']))
{ $pageNow=$_GET['pageNow'];}
$pageCount=0;
$sql="select count(Emp_id) from emp";
$res1=mysql_query($sql);
if($row=mysql_fetch_row($res1))
{$rowCount=$row[0];
$pageCount=ceil($rowCount/$pageSize);
/*if($rowCount%$pagesize==0){
$pageCount=$rowCount/$pagesize;
}else{
$pageCount=ceil($rowCount/$pagesize);
}*/
$sql="select * fromemp limit ".($pageNow-1)*$pageSize.",$pageSize";
echo "<table border='1px' bordercolor='green' cellspacing='0px' ;";
echo "<tr><th>Emp_id</th><th>Emp_name</th><th>Emp_grade</th><th>Emp_email</th><th>Emp_salary</th><th>修改用户</th><th>删除用户</th></tr>";
//循环显示用户的信息
while($row=mysql_fetch_assoc($res))
echo"<tr><td>{$row['Emp_id']}</td><td>{$row['Emp_name']}</td><td>{$row['Emp_grade']}</td><td>{$row['Emp_email']}</td><td>{$row['Emp_salary']}</td>".
"<td><a href='#'>修改用户</td><td><a href='#'>删除用户</td></tr>";
echo "<h1>雇员信息列表</h1>";
echo "</table>";
//打印出页面的超链接
for($i=1;$i<=$pageCount;$i++)
{echo "<a href='emplist.php?pageNow=$i'>$i$nbsp ";
<a href="http://guojiping.blog.51cto.com/attachment/201401/12/5635432_1389498493Ilme.png" target="_blank"></a>
参考传智播客,做的笔记及其测试!
后面会有mvc的实现模式!(敬请关注!!!)
本文转自 gjp0731 51CTO博客,原文链接:
http://blog.51cto.com/guojiping/1350962