当前位置:Gxlcms > 数据库问题 > 雇员信息管理系统(2)管理员数据库登录

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

时间:2021-07-01 10:21:17 帮助过:32人阅读

<!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

 

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

标签:消息   php   账号密码   显示   img   表单   sse   width   需要   

人气教程排行