韩顺平php雇员管理系统基础问题

sunen 2018-01-26 08:59:53
最近在看教程,跟着走到这一步,输入的用户名密码正确,还是提示错误,恳请大家指正

####################登陆页处理loginProcess.php###################
<?php 
require_once 'adminService.calss.php';
$id=$_POST['id'];
$password=$_POST['password'];

//实例化一个adminService方法
$adminService=new adminService();
if ($name=$adminService->checkAdmin($id,$password)) {
//合法
header('Location:empManage.php?name=$name');
exit();
}else{
//非法
header('Location:login.php?err=1');
}


?>

####################管理表验证逻辑adminService.calss.php###################
<?php 
require_once 'sqlHelper.class.php';
//该类是一个业务逻辑处理类,完成对admin表的各项操作
class adminService{
//提供一个验证用户是否合法的方法
public function checkAdmin($id,$password){
$sql="select password,name from admin where id=$id";
$sqlHelper=new sqlHelper();
$res=$sqlHelper->excute_dql($sql);
if ($row=mysql_fetch_assoc($res)) {
if (md5($password)==($row['password'])) {
return $row['name'];
}
}
mysql_free_result($res);
$sqlHelper->close();
return "";
}
}


?>

###########################数据库操作文件sqlHelper.class.php##################
<?php 
class sqlHelper{
public $conn;
public $host='localhost';
public $username='root';
public $password='root';
public $dbname='empManage';
public function db_connect(){
$this->conn=mysql_connect($this->host,$this->username,$this->password);
if (!$this->conn) {
die("数据库连接失败".mysql_errno());
}
mysql_select_db($this->dbname,$this->conn);
}

//执行dql语句
public function excute_dql($sql){
$res=mysql_query($sql,$this->conn);
return $res;
}
//执行dml语句
public function excute_dml($sql){
$b=mysql_query($sql,$this->conn);
if(!$b){
return 0;
}else{
if(mysql_fetch_row($b)>0){
return 1; //表示执行ok
}else{
return 2; //表示没有行收到影响
}
}
}
//关闭连接
public function close(){
mysql_close($this->conn);
}
}


?>

###########################登陆页面####################
<html>
<head><meta http-equiv="content-type" content="text/html;charset=utf-8"></head>
<h1>管理员登陆系统</h1>
<form action="loginProcess.php" method="post">
<tr>
<td>用户名:</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>
</form>
<?php
if (!empty($_GET['err'])) {
$err=$_GET['err'];
if ($err==1) {
echo "<font color=red size=5>用户名密码错误!</font>";
}
}
?>
</html>
...全文
264 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
sunen 2018-01-27
  • 打赏
  • 举报
回复
问题已找到,谢谢

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧