雇员信息管理系统(2)管理员数据库登录

运行结果如下:

  登录页面loginview.php。

 

  按下登录按钮,跳转到登录处理页面loginview.phploginprocess.php,进行数据库查询后,登录失败,跳转回登录页面loginview.php,并提示错误信息。

 

   输入正确的账号密码,登录成功,跳转到主页面mainview.php。

 

使用phpMyAdmin创建雇员信息管理数据库(aedb)过程如下:

  创建雇员信息管理数据库(aedb)。

 

  在雇员信息管理数据库(aedb)中,创建管理员表(ad)。

   在管理员表(ad)中,插入元组。

  (注:md5()用于加密。下例字符串参数”123“经过md5函数运算后将得到另一个字符串(称为md5值),无法解密,由此起到加密保护的作用。用于密码验证时,需要求出用户输入密码的md5值,若数据库中经过md5加密的密码与之相同,则验证成功。)

 

loginview.php源代码如下:

 1 <!DOCTYPE html>
 2 <html>
 3 <head>
 4     <title>雇员信息系统</title>
 5     <meta http-equiv = "content-type" content="text/html; charset = utf-8 ">
 6 
 7     <style type="text/css">
 8         div.error{height: 22px; width: 150px; color:red; size:2px;}
 9     </style>
10 
11 </head>
12 <body bgcolor="#ABC">
13     <center>
14         <div style="height: 60px; width: 50px"></div>
15         <!--用于调整表单的垂直位置-->
16         <h1 >管理员登录</h1>
17         <form action="loginprocess.php" method="post" >
18             <table>
19                 <tr>
20                     <th>账号</th>
21                     <th><input type="text" name="id"></input></th>
22                     <th><div class="error"><?php 
23                     //div,防止表单错误信息影响布局
24                     //判断表单错误信息的存在和显示
25                         if (isset($_GET['error'])) {
26                             $error=$_GET['error'];
27                         }else{
28                             $error=0;
29                         }
30                         if ($error==1) {
31                             echo"*账号或密码错误!";
32                         }
33                     ?></div></th>
34                 </tr>
35                 <!--tr标签内是同一行的内容,th标签内是同一列的内容-->
36                 <tr>
37                     <th>密码</th>
38                     <th><input type="password" name="password"></input></th>
39                 </tr>
40                 <tr>
41                     <th></th>
42                     <th>
43                         <input type="submit" value="登录"></input>
44                         <input type="reset" value="重置"></input>
45                     </th>
46                 </tr>
47             </table>
48         </form>
49     </center>
50 </body>
51 </html>
loginview.php

 

loginprocess.php源代码如下:

 1 <?php
 2 ////设置php文件的编码
 3     header("Content-type:text/html;charset=utf-8");
 4 //接受用户数据
 5     $id=$_POST['id'];
 6     $password=$_POST['password'];
 7 //得到连接
 8     $conn=mysql_connect("localhost","root","root");
 9     if (!$conn) {
10         die("连接失败!错误信息:".mysql_errno());
11     }
12 //设置访问数据库的编码
13     mysql_query("set names utf8",$conn) or die("设置编码失败!错误信息:".mysql_errno());
14 //选择数据库
15     mysql_select_db("aedb",$conn) or die("选择数据库失败!错误信息:".mysql_errno());
16 //发送SQL语句
17     $sql="SELECT password FROM ad WHERE id=$id";
18 //获取查询结果集
19     $res=mysql_query($sql,$conn);
20 //判断查询结果是否存在及是否完全匹配
21 //md5(),计算机安全领域广泛使用的一种散列函数,用以提供消息的完整性保护。
22     if (($row=mysql_fetch_assoc($res)) && $row['password']==md5($password)) {
23 //匹配成功,跳转到mainview.php
24         header("Location:mainview.php");
25         die();
26     }
27 //匹配失败,跳转到loginview.php,并发送错误信息error
28         header("Location:loginview.php?error=1");
29         die();
30 ?>
loginprocess.php

 

mainview.php源代码如下:

 1 <!DOCTYPE html>
 2 <html>
 3 <head>
 4     <title>欢迎使用雇员信息管理系统</title>
 5     <meta http-equiv = "content-type" content="text/html; charset = utf-8 ">
 6 
 7     <style type="text/css">
 8         div.d0{color:red; size:200px; font-weight:700;text-align:center;}
 9     </style>
10 
11 </head>
12 <body bgcolor="#ABC" >
13     <div class="d0">登录成功!!</div>
14 </body>
15 </html>
mainview.php

 

转载于:https://www.cnblogs.com/maguariji/p/7235389.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值