您的位置:首页 > 其它

64. 雇员管理系统

2015-11-21 17:11 218 查看
项目开发阶段



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>
<?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'];

if($id == '100'  && $password =='123'){
//合法,跳转到empManage.php
header('Location:empManage.php');
//跳转后要退出,最好退出,退出进程,一个请求对应一个进程
exit();
}else{
//非法,跳转回去
header('Location:login.php?errno=1');//带点信息给login.php
exit();
}


empManage.php

<?php
header('Content-Type:text/html;charset=utf-8');
echo "登陆成功<br/>";
echo "<br/><a href='login.php'>返回重新登陆</a>";
?>


到数据库验证:

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 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){
//说明合法
header('Location:empManage.php');
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>
<h1>主页面</h1>
<a href="">管理用户</a>
<a href="">添加用户</a>
<a href="">查询用户</a>
<a href="">退出系统</a>
</body>
</html>

<?php
header('Content-Type:text/html;charset=utf-8');
echo "登陆成功<br/>";
echo "<br/><a href='login.php'>返回重新登陆</a>";
?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: