【PHP小项目使用MVC架构】-程序员宅基地

技术标签: 测试  php  数据库  

小项目名称是雇员管理系统。

mvc是一种项目的开发模式,中文名称为模式视图控制器,是强制程序员将数据的输入、处理、输出分开的一种开发模式。

在这个小项目中,控制器使用service作为后缀名。

项目uml图解概述:

在此之前,需要先创建数据库empmanage,同时创建两张表,一张表为admin,令一张表为emp,创建admin表的sql语句:

create table admin
(
id int primary key,
name varchar(32) not null,
password varchar(64) not null
);

create table emp(
id int primary key auto_increment,
name varchar(64) not null,
grade  tinyint /****1表示1级工人,2表示2级工人*****/,
email varchar(64) not null,
salary float
);
View Code

按照字段名向admin表插入1条管理员用户数据,向emp表插入几万条数据即可,向emp表插入数据的时候使用mysql的蠕虫复制功能,分分钟就可以搞定。

将root密码改为5a6f38,否则连接不到数据库。

下面将会将文件名以及文件中的源代码介绍给大家。

login.php

 1 <?php
 2 require_once 'common.php';
 3 ?>
 4 <html>
 5 <head>
 6 <meta http-equiv="content-type" content="text/html;charset=utf-8"/>
 7 </head>
 8 <!--此版本完成了验证码验证的问题-->
 9 
10 <body>
11 <h1>管理员登陆界面</h1>
12 <form action="loginProcess.php" method="post">
13 <table>
14 <tr>
15 <td>请输入用户id:</td>
16 <td><input type="text" name="admin_id" value="<?php echo getUserName();?>"/></td>
17 </tr>
18 
19 <tr>
20 <td>请输入用户密码:</td>
21 <td><input type="password" name="admin_password" value="<?php echo getPassword();?>"/></td>
22 </tr>
23 
24 <tr>
25 <td>请输入验证码:</td>
26 <td><input type="text" name="checkCode"/></td>
27 <td><img src="checkCode.php" οnclick="this.src='checkCode.php?re='+Math.random()"/></td>
28 </tr>
29 <tr>
30 <td colspan="2">
31 两周内免登陆本系统:
32 <input type="checkbox" name="userinf" value="on" checked="checked"/>
33 </td>
34 </tr>
35 
36 <tr>
37 <td><input type="submit" value="单击登陆"/></td>
38 <td><input type="reset" value="重新填写"/></td>
39 </tr>
40 </table>
41 </form>
42 
43 <?php
44 $error="初始值";
45 $error=$_GET['error'];//使用header传递参数,默认的提交方式是GET
46 echo "<font color=red>".$error."</font>";
47 ?>
48 </body>
49 </html>
View Code

addEmp.php

 1 <?php
 2 /**
 3  * 进行用户验证
 4  */
 5 require_once 'common.php';
 6 checkUser(); 
 7 ?>
 8 
 9 
10 <html>
11 <!--这个是专门针对添加用户设计的界面-->
12 <head>
13 <meta http-equiv="content-type" content="text/html;charset=utf-8"/>
14 </head>
15 <body>
16 <center><h1><font size='30px'>这里是添加用户的界面</font></h1></center>
17 <br/>
18 <br/>
19 <form action="empProcess.php" method="post">
20 <table align="center" cellpadding="10px">
21 
22 <tr align="center">
23 <td>请输入姓名:</td>
24 <td><input type="text" name="name"/></td>
25 </tr>
26 
27 <tr align="center">
28 <td>请输入您的等级:</td>
29 <td><input type="text" name="grade"/></td>
30 </tr>
31 
32 <tr align="center">
33 <td>请输入您的邮箱:</td>
34 <td><input type="text" name="email"/></td>
35 </tr>
36 
37 <tr align="center">
38 <td>请输入您的薪水:</td>
39 <td><input type="text" name="salary"/></td>
40 </tr>
41 <input type="hidden" name="type" value="add"/>
42 <tr align="center">
43 <td><input type="submit" name="submit" value="单击提交" /></td>
44 <td><input type="reset" name="reset" value="重新输入" /></td>
45 </tr>
46 <tr>
47 <td colspan="2"><a href="empMain.php?name=admin">单击返回上一级</a></td>
48 </tr>
49 </table>
50 </form>
51 </body>
52 </html>
View Code

Admin.class.php

 1 <?php
 2 class Admin 
 3 {
 4     private $id;
 5     private $name;
 6     private $password;
 7     public function getid()
 8     {
 9         return $this->id;
10     }
11     public function setid($id)
12     {
13         $this->id=id;
14     }
15     public function getname()
16     {
17         return $this->name;
18     }
19     public function setname($name)
20     {
21         $this->name=$name;
22     }
23     public function getpassword()
24     {
25         return $this->password;
26     }
27     public function setpassword($password)
28     {
29         $this->password=$password;
30     }
31 }
32 ?>
View Code

AdminService.class.php

 1 <?php
 2 require_once 'SqlHelper.class.php';
 3 class AdminService
 4 {
 5     public function checkAdmin($get_id,$get_password)
 6     {
 7         $sql="select password from admin where id='".$get_id."'";
 8         //建立一个SqlHelper.class.php对象
 9         $sqlhelper=new SqlHelper("localhost","root","5a6f38","empmanage");
10         $res=$sqlhelper->dql($sql);
11         $row=mysql_fetch_assoc($res);
12         mysql_free_result($res);
13         mysql_close($sqlhelper->conn);
14         if($row)
15         {
16             $password=$row['password'];
17             if(md5($get_password)==$password)
18             {
19                 return 1;
20             }
21             return 0;
22         }
23         return 0;
24     }
25     public function getName($id)
26     {
27         $sqlhelper=new SqlHelper("localhost","root","5a6f38","empmanage");
28         $sql="select name from admin where id='".$id."'";
29         $res=$sqlhelper->dql($sql);
30         $row=mysql_fetch_assoc($res);
31         if($row)
32         {
33             mysql_free_result($res);
34             mysql_close($sqlhelper->conn);
35             return $row['name'];
36         }
37         die("查无此人!");
38     }
39 }
40 ?>
View Code

checkCode.php

 1 <?php
 2     //首先定义一个空字符串
 3     $checkCode="";
 4     //随机生成四个数并拼接起来
 5     for($i=1;$i<=4;$i++)
 6     {
 7         $checkCode.=rand(0,9);
 8     }
 9     session_start();
10     $_SESSION['checkCode']=$checkCode;
11     //开始绘制验证码
12 
13     //1.生成画布
14     $im=imagecreatetruecolor(45,25);
15     //2.随机生成一个颜色
16     $color=imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255));
17     //$color=imagecolorallocate($im,255,0,0);
18 
19     //3.绘制干扰线
20     for($i=1;$i<=20;$i++)
21     {
22         imageline($im,0,rand(0,24),44,rand(0,24),imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255)));
23     }
24     //4.绘制字符串
25     imagestring($im,5,3,3,$checkCode,$color);
26     header("content-type: image/png");
27     imagepng($im);
28 
29     //4.销毁图片
30     imagedestroy($im);
31 ?>
View Code

common.php

 1 <?php
 2 /**
 3  * 这个方法专门用于用户判断
 4  */
 5 function checkUser()
 6 {
 7     session_start();
 8     if(empty($_SESSION['name']))
 9     {
10         header("Location:login.php?error=请先登录在进行其他操作!");
11         exit();
12     }
13 }
14 /**
15  * 这个类中专门存放公共的方法,如取cookie等行为
16  */
17 function getUserName()
18 {
19     if(!empty($_COOKIE['name']))
20     {
21         return $_COOKIE['name'];
22     }    
23     else 
24     {
25         return "";
26     }
27 }
28 function getPassword()
29 {
30     if(!empty($_COOKIE['password']))
31     {
32         return $_COOKIE['password'];
33     }
34     else
35     {
36         return "";
37     }
38 }
39 function getLastTime()
40 {
41     date_default_timezone_set("Asia/Chongqing");
42     if(empty($_COOKIE['lasttime']))
43     {
44         setCookie("lasttime",date("Y年m月d日 H时m分s秒"),Time()+14*24*3600);
45         echo  "您是第一次登陆本系统!";
46     }
47     else 
48     {
49         setCookie("lasttime",date("Y年m月d日 H时m分s秒"),Time()+14*24*3600);
50         echo "您上一次的登录时间是:".$_COOKIE['lasttime'];
51     }
52 }
53 ?>
View Code

Emp.class.php

 1 <?php
 2 class Emp
 3 {
 4     private $id;
 5     private $name;
 6     private $grade;
 7     private $email;
 8     private $salary;
 9     public function setid($id)
10     {
11         $this->id=$id;
12     }
13     public function getid()
14     {
15         return $this->id;
16     }
17     public function setname($name)
18     {
19         $this->name=$name;
20     }
21     public function getname()
22     {
23         return $this->name;
24     }
25     public function setgrade($grade)
26     {
27         $this->grade=$grade;
28     }
29     public function getgrade()
30     {
31         return $this->grade;
32     }
33     public function setemail($email)
34     {
35         $this->email=$email;
36     }
37     public function getemail()
38     {
39         return $this->email;
40     }
41     public function setsalary($salary)
42     {
43         $this->salary=$salary;
44     }
45     public function getsalary()
46     {
47         return $this->salary;
48     }
49 }
50 ?>
View Code

empList.php

  1 <?php
  2 /**
  3  * 进行用户验证
  4  */
  5 require_once 'common.php';
  6 checkUser(); 
  7 ?>
  8 <html>
  9 <head>
 10 <script type="text/javascript">
 11 function confirmDel(val)
 12 {
 13     return window.confirm("确认删除"+val+"号雇员吗?");
 14 }
 15 </script>
 16 </head>
 17 <body>
 18 <?php
 19     require_once 'EmpService.class.php';
 20     //本子功能主要知识点:分页管理功能,可以使用死去活来法逐步实现。
 21     echo "<center>";
 22     echo "<h1>用户管理</h1><br/>";
 23     $empservice=new EmpService();
 24     //获取emp表的记录数。
 25     $rowCount=$empservice->getRowCount();
 26     //设置pageNow的默认值。
 27     $pageNow=1;
 28     //获取pageNow的值
 29     if($_GET['pageNow'])
 30     {
 31         $pageNow=$_GET['pageNow'];
 32     }
 33     //设置$pageSize的默认值,可以由用户自定义
 34     $pageSize=7;
 35     //计算pageCount的值
 36     $pageCount=ceil($rowCount/$pageSize);
 37     if($pageNow<=0)
 38     {
 39         echo "访问出现上溢,自动跳转到第一页!<br/><br/>";
 40         $pageNow=1;
 41     }
 42     else if($pageNow>=($pageCount+1)) 
 43     {
 44         echo "访问出现下溢,自动跳转到最后一页!<br/><br/>";
 45         $pageNow=$pageCount;
 46     }
 47     $arr_res=$empservice->getResource($pageNow, $pageSize);
 48     $rows=mysql_affected_rows($empservice->getSqlHelper()->conn);
 49     $cols=mysql_num_fields($empservice->getResource_unArray());
 50     
 51 
 52     echo "<table bgcolor=black rows=".($rows+1)." cols=".($cols+2)." cellspacing=1px cellpadding=10px>";
 53     echo "<tr bgcolor=white>";
 54     for($i=0;$i<$cols;$i++)
 55     {
 56         echo "<th>".mysql_field_name($empservice->getResource_unArray(),$i)."</th>";
 57     }
 58     echo "<th>修改用户信息</th>";
 59     echo "<th>删除用户</th>";
 60     echo "</tr>";
 61     for($i=0;$i<count($arr_res);$i++)
 62     {
 63         $row=$arr_res[$i];
 64         echo "<tr bgcolor=white>";
 65         foreach($row as $key=>$value)
 66         {
 67             echo "<td align=center>".$value."</td>";
 68         }
 69         echo "<td align=center><a href='updateEmpUI.php?id={
     $row['id']}'>修改</a></td>";
 70         echo "<td align=center><a οnclick=
 71         'return confirmDel({
     $row['id']})' 
 72         href='empProcess.php?type=del&id={
     $row['id']}
 73         &pageNow={
     $pageNow}'>删除</a></td>";
 74         echo "</tr>";
 75     }
 76     echo "</table><br/>";
 77     $empservice->closeAll();
 78     echo "<a href='empList.php?pageNow=1'>首页</a>&nbsp;&nbsp;&nbsp;";
 79     if($pageNow>=2)
 80     {
 81         echo "<a href='empList.php?pageNow=".($pageNow-1)."'>上一页</a>&nbsp;&nbsp;&nbsp;";
 82     }
 83     else 
 84     {
 85         echo "上一页&nbsp;&nbsp;&nbsp;";
 86     }
 87     //一下将会实现6页6页的整体翻页。
 88      $index=floor(($pageNow-1)/6)*6+1;
 89      $start=$index;
 90      echo "<a href='empList.php?pageNow=".($start-1)."'><<</a>&nbsp;&nbsp;&nbsp;";
 91     for(;$start<=5+$index;$start++)
 92     {
 93         if($start<=$pageCount)
 94         {
 95             echo "<a href='empList.php?pageNow=".$start."'>[".$start."]";
 96             echo "</a>"."&nbsp;&nbsp;&nbsp;";
 97         }
 98         else 
 99         {
100             $start--;
101             break;
102         }
103     }
104     /**
105      * 如果有6条记录,现在是第2条,那么2/6=0.33,floor(0.33)==0,
106      * ...什么时候打印?求打印条件。
107      */
108     echo "...&nbsp;&nbsp;&nbsp;";
109     echo "[当前页{
     $pageNow}/共{
     $pageCount}页]&nbsp;&nbsp;&nbsp;";
110     echo "<a href='empList.php?pageNow=".$start."'>>></a>&nbsp;&nbsp;&nbsp;";
111     if($pageNow<=($pageCount-1))
112     {
113         echo "<a href='empList.php?pageNow=".($pageNow+1)."'>后一页</a>&nbsp;&nbsp;&nbsp;";
114     }
115     else 
116     {
117         echo "后一页&nbsp;&nbsp;&nbsp;";
118     }
119     echo "<a href='empList.php?pageNow=".$pageCount."'>尾页</a>";
120     echo "<br/>";
121 ?>
122 <br/>
123 <form action="empList.php" method="get">
124 请输入跳转页:<input type="text" name="pageNow"/>
125 <input type="submit" value="GO"/>
126 </form>
127 
128 </body>
129 </html>
View Code

empMain.php

 1 <?php
 2 
 3 /**
 4  * 进行用户验证
 5  */
 6 require_once 'common.php';
 7 checkUser();
 8 
 9 
10     $admin_name=$_GET['name'];
11     require_once 'common.php';
12     getLastTime();
13     echo "<center>";
14     if(!$admin_name)
15     {
16         die("没有收到用户名数据!");    
17     }
18     else 
19     {
20         echo "<font size='7'>".$admin_name.",欢迎您登陆本系统!<br/><br/>";
21         echo "</font>";
22     }
23 
24     echo "<font size='5'>";
25     echo "<a href='empList.php'>管理用户</a><br/><br/>";
26     echo "<a href='addEmp.php'>添加用户</a></a><br/><br/>";
27     echo "<a href='#'>等待添加</a></a><br/><br/>";
28     echo "<a href='#'>等待添加</a></a><br/><br/>";
29     echo "</font size='5'>";
30     echo "</center>";
31 ?>
View Code

empProcess.php

 1 <?php
 2 /**
 3  * 进行用户验证
 4  */
 5 require_once 'common.php';
 6 checkUser();
 7 
 8 require_once 'EmpService.class.php';
 9 
10 $type=$_REQUEST['type'];
11 if($type=="del")
12 {
13     $id=$_GET['id'];
14     $pageNow=$_GET['pageNow'];
15     if(empty($id))
16     {
17         die("没有收到雇员的ID号数据!");
18     }
19     //创建一个EmpService的对象
20     $empservice=new EmpService();
21     $flag=$empservice->deleteUser($id);
22     if($flag==1)
23     {
24         header("Location:success.php?id={
     $id}&pageNow={
     $pageNow}");
25         exit();
26     }
27     header("Location:error.php?id={
     $id}");
28     exit();
29 }
30 else
31     if($type=="add")
32     {
33         $empService=new EmpService();
34         $name=$_POST['name'];
35         $grade=$_POST['grade'];
36         $email=$_POST['email'];
37         $salary=$_POST['salary'];
38         $result=$empService->addEmp($name, $grade, $email, $salary);
39         if($result!=1)
40         {
41             die("添加用户失败!".mysql_errno());
42         }
43         else 
44         {
45             echo "添加成功!<a href='addEmp.php'>返回上一级</a>";
46         }
47     }
48 else 
49     if($type=="update")
50     {
51         $empService=new EmpService();
52         $id=$_POST['id'];
53         $name=$_POST['name'];
54         $grade=$_POST['grade'];
55         $email=$_POST['email'];
56         $salary=$_POST['salary'];
57         $result=$empService->updateEmp($name, $grade, $email, $salary,$id);
58         if($result!=1)
59         {
60             die("更新用户信息失败!".mysql_errno());
61         }
62         else
63         {
64             echo "更新用户信息成功!<a href='updateEmpUI.php?id={
     $id}'>返回上一级</a>";
65         }
66     }
67 
68 ?>
View Code

EmpService.class.php

  1 <?php
  2 require_once 'SqlHelper.class.php';
  3 require_once 'Emp.class.php';
  4 class EmpService
  5 {
  6     private $sqlhelper;
  7     private $res;
  8     public function __construct()
  9     {
 10         $this->sqlhelper=new SqlHelper("localhost","root","5a6f38", "empmanage");
 11     }
 12     /**
 13      * 这个方法专门用于更新雇员信息
 14      */
 15     public function updateEmp($name, $grade, $email, $salary,$id)
 16     {
 17         $sql="update emp set name='{
     $name}',grade={
     $grade},
 18         email='{
     $email}',salary={
     $salary} where id={
     $id}";
 19         $result=$this->sqlhelper->dml($sql);
 20         mysql_close($this->sqlhelper->conn);
 21         return $result;
 22     }
 23     /**
 24      * 这个方法通过ID号取得雇员的其他信息
 25      */
 26     public function getEmpById($id)
 27     {
 28         $emp=new Emp();
 29         $sql="select * from emp where id={
     $id}";
 30         $this->res=$this->sqlhelper->dql($sql);
 31         if(!$this->res)
 32         {
 33             die("查询失败!".mysql_errno());
 34         }
 35         if(($row=mysql_fetch_assoc($this->res))!=null)
 36         {
 37             $emp->setid($row['id']);
 38             $emp->setemail($row['email']);
 39             $emp->setgrade($row['grade']);
 40             $emp->setname($row['name']);
 41             $emp->setsalary($row['salary']);
 42         }
 43         $this->closeAll();
 44         return $emp;
 45     }
 46     /**
 47      * 这个方法是专门针对添加用户的方法
 48      */
 49     public function addEmp($name,$grade,$email,$salary)
 50     {
 51         $sql="insert into emp(name,grade,email,salary) values ('{
     $name}',{
     $grade},'{
     $email}',{
     $salary})";
 52         //$this->sqlhelper=new SqlHelper("localhost", "root","5a6f38", "empmanage");
 53         $result=$this->sqlhelper->dml($sql);
 54         mysql_close($this->sqlhelper->conn);
 55         return $result;
 56     }
 57     public function getRowCount()
 58     {
 59         $sql="select count(*) from emp";
 60         $res=$this->sqlhelper->dql($sql);
 61         if(!$res)
 62         {
 63             die("查询失败!");
 64         }
 65         $row=mysql_fetch_row($res);
 66         $rowCount=$row[0];
 67         return $rowCount;
 68     }
 69     public function getResource($pageNow,$pageSize)
 70     {
 71         $x=($pageNow-1)*$pageSize;
 72         $sql="select * from emp order by id limit ".$x.",".$pageSize;
 73         $res=mysql_query($sql,$this->sqlhelper->conn);
 74         $this->res=$res;
 75         if(!$res)
 76         {
 77             die("获取资源失败!");
 78         }
 79         $arr=Array();//效仿discuz的写法,这是05版本的改进之处。
 80         $top=-1;
 81         while(($row=mysql_fetch_assoc($res))!=null)
 82         {
 83             $arr[++$top]=$row;
 84         }
 85         return $arr;
 86     }
 87     public function getSqlHelper()
 88     {
 89         return $this->sqlhelper;
 90     }
 91     public function getResource_unArray()
 92     {
 93         return $this->res;
 94     }
 95     public function closeAll()
 96     {
 97         mysql_free_result($this->res);
 98         mysql_close($this->sqlhelper->conn);
 99     }
100     public function closeConn()
101     {
102         mysql_close($this->sqlhelper->conn);
103     }
104     public function deleteUser(&$id)
105     {
106         $sql="delete from emp where id={
     $id}";
107         return $this->sqlhelper->dml($sql);
108     }
109 }
110 ?>
View Code

error.php

1 <?php
2 echo "删除失败!";
3 ?>
View Code

loginProcess.php

 1 <?php
 2 // print_r($_COOKIE);
 3 require_once 'AdminService.class.php';
 4 $admin_id=$_POST['admin_id'];
 5 $admin_password=$_POST['admin_password'];
 6 $userinf=$_POST['userinf'];//记录用户是否要求浏览器记住用户密码
 7 $checkCode=$_POST['checkCode'];
 8 session_start();
 9 
10 if($checkCode!=$_SESSION['checkCode'])
11 {
12     header("Location:login.php?error=验证码输入错误,请重新输入!");
13     exit();
14 }
15 if(empty($userinf))//用户不允许记住用户名和密码
16 {
17 //     echo "用户不允许记住账号密码<br/>";
18     //查看以前是否有cookie记录,如果有,则删除全部
19     if(!empty($_COOKIE['name']))
20     {
21 //         echo "将会删除cookie<br/>";
22         setCookie("name",$admin_id,Time()-14*24*3600);
23         setCookie("password",$admin_password,Time()-14*24*3600);
24         setCookie("lasttime",date("Y年m月d日 H时m分s秒"),Time()-14*24*3600);
25     }
26 }
27 else //用户允许记住用户名和密码
28 {
29 //     echo "用户允许浏览器记住账号密码<br/>";
30     //先查看cookie中是否有以前的记录,如果有,显示上一次登录的时间;反之
31     //提示是首次登陆,并保存住账号密码
32     if(empty($_COOKIE['name']))//
33     {
34 //         echo "将会创建cookie<br/>";
35         setCookie("name",$admin_id,Time()+14*24*3600);
36         setCookie("password",$admin_password,Time()+14*24*3600);
37     }
38 }
39 // exit();
40 
41 $adminservice=new AdminService();
42 $flag=$adminservice->checkAdmin($admin_id, $admin_password);
43 if($flag==1)
44 {
45     session_start();
46     /**
47         将数据保存到session中,进行用户登录校验
48      */
49     $_SESSION['name']=$admin_id;
50     header("Location:empMain.php?name=".$adminservice->getName($admin_id));
51     exit();
52 }
53 else
54 {
55     header("Location:login.php?error=用户名或者密码错误,请重新输入!");
56     exit();
57 }
58 ?>
View Code

SqlHelper.class.php

 1 <?php
 2 class SqlHelper
 3 {
 4     public $host;
 5     public $user;
 6     public $psw;
 7     public $dbname;
 8     public $conn;
 9     public function __construct($host,$user,$psw,$dbname)
10     {
11         $this->host=$host;
12         $this->user=$user;
13         $this->psw=$psw;
14         $this->dbname=$dbname;
15         $this->conn=mysql_connect($this->host,$this->user,$this->psw);
16         if(!$this->conn)
17         {
18             die("数据库连接失败!".mysql_error());
19         }
20         mysql_select_db($this->dbname);
21         mysql_query("set names utf8",$this->conn);
22     }
23     public function dql($sql)
24     {
25         $res=mysql_query($sql,$this->conn);
26         if(!$res)
27         {
28             die("查询失败!".mysql_error());
29         }
30         else return $res;
31     }
32     public function dml($sql)
33     {
34         $res=mysql_query($sql,$this->conn);
35         if(!$res)
36         {
37             die("数据更新失败!".mysql_error());
38         }
39         else if(mysql_affected_rows($this->conn))
40         {
41             return 1;
42         }
43         else 
44         {
45             return 2;
46         }
47     }
48 }
49 ?>
View Code

success.php

1 <?php
2     $pageNow=$_GET['pageNow'];
3     echo "删除成功!";
4     echo "<a href='empList.php?pageNow={
     $pageNow}'>返回上一级</a>";
5 ?>
View Code

updateEmpUI.php

 1 <?php
 2 /**
 3  * 进行用户验证
 4  */
 5 require_once 'common.php';
 6 checkUser(); 
 7 ?>
 8 <html>
 9 <!--这个是专门针对更新用户信息设计的界面-->
10 <head>
11 <meta http-equiv="content-type" content="text/html;charset=utf-8"/>
12 </head>
13 <body>
14 <?php
15 require_once 'Emp.class.php';
16 require_once 'EmpService.class.php';
17 $id=$_GET['id'];
18 //获得其他参数。
19 $empService=new EmpService();
20 //获取Emp对象。
21 $emp=$empService->getEmpById($id);
22 ?>
23 <center><h1><font size='30px'>这里是更新用户信息的界面</font></h1></center>
24 <br/>
25 <br/>
26 <form action="empProcess.php" method="post">
27 <table align="center" cellpadding="10px">
28 <tr align="center">
29 <td>您的ID是:</td>
30 <td><input readonly="readonly" type="text" name="id" value="<?php echo $emp->getid()?>"/></td>
31 </tr>
32 
33 <tr align="center">
34 <td>请输入您的新姓名:</td>
35 <td><input type="text" name="name" value="<?php echo $emp->getname()?>"/></td>
36 </tr>
37 
38 <tr align="center">
39 <td>请输入您的新等级:</td>
40 <td><input type="text" name="grade" value="<?php echo $emp->getgrade()?>"/></td>
41 </tr>
42 
43 <tr align="center">
44 <td>请输入您的新邮箱:</td>
45 <td><input type="text" name="email" value="<?php echo $emp->getemail()?>"/></td>
46 </tr>
47 
48 <tr align="center">
49 <td>请输入您的新薪水:</td>
50 <td><input type="text" name="salary" value="<?php echo $emp->getsalary()?>"/></td>
51 </tr>
52 <input type="hidden" name="type" value="update"/>
53 <tr align="center">
54 <td><input type="submit" name="submit" value="单击提交" /></td>
55 <td><input type="reset" name="reset" value="重新输入" /></td>
56 </tr>
57 <tr>
58 <td colspan="2"><a href="empMain.php?name=admin">单击返回上一级</a></td>
59 </tr>
60 </table>
61 </form>
62 </body>
63 </html>
View Code

这个小项目还只是个半成品。仅仅完成了对雇员的增删改功能,查找功能还未实现。但是实现了cookie、session、验证码的小功能。特别是小项目是采用的mvc架构,这就大大增加了开发难度但是代码复用性大大提高了。

项目截图:

转载于:https://www.cnblogs.com/kuangdaoyizhimei/p/3970255.html

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/anpin1976/article/details/102415555

智能推荐

使用Python Falcon框架快速实现简单API-程序员宅基地

文章浏览阅读5.9k次。Ubuntu下默认装了python2.7装pip(安装python包管理器)sudo apt-get install python-pip装Falcon和gunicorn(gunicorn是一个Python WSGI UNIX的HTTP服务器)pip install --upgrade falconpip install gunicorn新建一个_python falcon框架

Linux下TFTP的安装,配置和操作-程序员宅基地

文章浏览阅读83次。注:转载他人,仅供自己研究学习使用TFTP是用来下载远程文件的最简单网络协议,它其于UDP协议而实现。嵌入式linux的tftp开发环境包括两个方面:一是linux服务器端的tftp-server支持,二是嵌入式目标系统的tftp-client支持。因为u-boot本身内置支持tftp-client,所以嵌入式目标系统端就不用配置了。 xinetd(eXtended InterNET..._"linux tftp安装43 rrq \"s5800_5820x-cmw520-r1810p16.bin\" netascii"

Python爬虫反反爬:CSS反爬加密彻底破解-程序员宅基地

文章浏览阅读794次。点击“简说Python”,选择“星标公众号”福利干货,第一时间送达!@老表家的猫本文授权转载自数据EDTA禁止二次转载大家好,我是老表阅读文本大概需要 10分钟今天,爬..._eetop 反爬虫

STM32芯片--FSMC外设扩展外部SRAM-程序员宅基地

文章浏览阅读7.4k次,点赞6次,收藏49次。这里写自定义目录标题为什么要扩展外部SRAM(一)什么是SRAM简介存储器型号容量引脚配置通讯方式读写特性读取数据时序图读取数据的时序要求写入数据时序图写入数据的时序要求(二)什么是FSMC外设简介功能快捷键合理的创建标题,有助于目录的生成如何改变文本的样式插入链接与图片如何插入一段漂亮的代码片生成一个适合你的列表创建一个表格设定内容居中、居左、居右SmartyPants创建一个自定义列表如何创建..._外部sram

新手用qt控件显示本地图片_qt实现拉取一个控件显示一张照片-程序员宅基地

文章浏览阅读6.8k次,点赞4次,收藏17次。QT显示图片的方法(部分源码)这个方法太简单网上已经泛滥了,不过我还是写一下吧,无聊。1 首先,新建一个项目,使用界面文件(可以不使用,不过人生苦短,没事我就不麻烦自己了)2使用qt设计器,在界面拖入一个label(我修改其objectname为screen)与一个button。3 转到button的槽,书写相应的程序。 程序如下 需要使用并添加的头文件部分#include#_qt实现拉取一个控件显示一张照片

【YOLOv4探讨 之三】mosaic数据增强_yolo mosaic-程序员宅基地

文章浏览阅读1w次,点赞17次,收藏51次。最近太忙,久未更新,对不住大家。进入正题,我们聊一聊YOLOv4中使用的mosaic数据增强。关于mosaic数据增强相关文章不少,三个月前这个方面的学习开了个头,那时候各路诸侯都是以TensorFlow框架为主,我这里依然坚持分析研究darknet框架下的数据增强。mosaic数据增强原理YOLOv4中在载入图片数据时同步进行mosaic数据增强。mosaic数据增强基本原理就是在训练集中随机选择若干个(一般是4个)图像,经过裁剪拼接形成新的训练集元素,可以缓解训练集元素少或者增强识别能力,是cut_yolo mosaic

随便推点

21计算机考研国家线,来了!21考研国家线公布!附详细解读!-程序员宅基地

文章浏览阅读3.3k次。原标题:来了!21考研国家线公布!附详细解读!21考研人最近大概都在焦虑的等待国家线昨天中国农业大学的一条消息直接将“考研国家线”顶上热搜!这不!最新出炉的国家线就来了!21考研国家线公布! 21国家线学硕总分线上涨的门类有:经济学、历史学、理学、工学、农学、工学照顾专业。21国家线专硕总分线上涨的专业有:金融、应用统计、税务、国际商务、保险、资产评估、审计、教育、汉语国际教育、应用心理、体育、会...

学习和安装 skyeye_skyeye漏扫-程序员宅基地

文章浏览阅读771次。如果你要使用不带MMU支持的交叉编译器的话,那么需要将vendors/config/armnommu/config.arch文件中“CROSS_COMPILE”的值由“arm-linux-”改为“arm-elf-”,否则下面的make menuconfig配置完成后会报告找不到arm-linux-gcc导致编译失败。[原文:http://www.linuxsir.org/bbs/sho_skyeye漏扫

彻底删除mysql服务(清理注册表)_清理mysql注册表-程序员宅基地

文章浏览阅读4.5k次,点赞4次,收藏10次。由于安装某个项目的执行文件,提示要卸载MySQL以便它自身MySQL安装,然后我禁用了MYSQL服务,再把这个文件夹删除后,发现还是提示请卸载MYSQL服务。解决步骤:1.以管理员身份运行命令提示符cmd,输入禁用服务方式:net stop mysql //停止服务这里的mysql是你服务中的mysql名(有些可能是mysql5,或者之类)。或者 我的电脑右键->管理->服务,进入后手动禁用。2.输入sc delete mysql,删除服务。3.此时,MYSQL服务只是显示禁用状态,_清理mysql注册表

案例-做一个酒店预定小程序用的日期选择案例_小程序订酒店日历选择-程序员宅基地

文章浏览阅读6.6k次,点赞3次,收藏39次。做一个酒店预定用的日期选择案例不多说,先上效果图设计思路:根据年份和月份构建最近6个月的日历,获取每个月的第一天是星期几,空白用空对象填充,每个月需要的格子数 = 每月1号的星期数 + 每月对应的天数。在HTML中遍历日期数据,根据条件判断高亮显示入住时间、离店时间以及两者之间的时间。一下是全部代码(优化在最后). &amp;amp;amp;lt;!-- html代码 --&amp;amp;amp;gt; &amp;amp;amp;lt;view..._小程序订酒店日历选择

lol佐伊美图-程序员宅基地

文章浏览阅读1.6k次。  心血来潮,分享一波从各个网站上搜集到的佐伊美图,持续更新!(最近更新日期:2019/07/01)  本页面图片较多,若无法全部加载请反复刷新页面,点击图片可查看原始大图!Section1 暮光星灵2018/11/162019/02/152019/03/172019/07/01Section2 ...

(基础入门)web安全|渗透测试|网络安全------附带 子域名挖掘,exe后门程序生成之Quasar,抓包wsexplorerv,逆向工具漏了个大洞-程序员宅基地

文章浏览阅读2.7k次,点赞9次,收藏12次。(基础入门)web安全|渗透测试|网络安全------附带 子域名挖掘,exe后门程序生成之Quasar,抓包wsexplorerv,逆向工具漏了个大洞

推荐文章

热门文章

相关标签