成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

php怎么實(shí)現(xiàn)簡(jiǎn)單的雇員管理系統(tǒng)

這篇文章主要講解了“php怎么實(shí)現(xiàn)簡(jiǎn)單的雇員管理系統(tǒng)”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來(lái)研究和學(xué)習(xí)“php怎么實(shí)現(xiàn)簡(jiǎn)單的雇員管理系統(tǒng)”吧!

成都創(chuàng)新互聯(lián)公司堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:網(wǎng)站建設(shè)、網(wǎng)站制作、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時(shí)代的饒平網(wǎng)站設(shè)計(jì)、移動(dòng)媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!

  這是一個(gè)簡(jiǎn)單的php練習(xí)小項(xiàng)目,因?yàn)楸容^簡(jiǎn)單所以就沒(méi)有用Smarty模板去把這個(gè)項(xiàng)目徹底的輸入,處理,輸出分離,只是簡(jiǎn)單的用MVC的設(shè)計(jì)模式去寫的。這個(gè)項(xiàng)目主要是為了練習(xí)Cookie和Session的使用。

  數(shù)據(jù)庫(kù)用的是MySQL,建了一個(gè)empmanage的數(shù)據(jù)庫(kù),里面有兩張表。如圖:

php怎么實(shí)現(xiàn)簡(jiǎn)單的雇員管理系統(tǒng)  

表的結(jié)構(gòu)如圖:

php怎么實(shí)現(xiàn)簡(jiǎn)單的雇員管理系統(tǒng)

php怎么實(shí)現(xiàn)簡(jiǎn)單的雇員管理系統(tǒng)

  php怎么實(shí)現(xiàn)簡(jiǎn)單的雇員管理系統(tǒng)

  這是登陸界面,因?yàn)橹饕刖毩?xí)后臺(tái)相關(guān)知識(shí),所以前臺(tái)頁(yè)面寫的比較簡(jiǎn)單。實(shí)際上是先寫的index.php,里面就只是一個(gè)跳轉(zhuǎn)。

 index.php

<?php 
	header("Location:login.php");
?>

  login.php

<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>emp_system</title>
</head>
<?php require_once 'common.php';?>
<h2>emp login</h2>
<form action="loginProcess.php" method="post">
用戶名<input type="text" name="username" value="<?php echo getCookie("username")?>"/><br/>
密碼 <input type="password" name="password"/><br/>
sava cookie<input type="checkbox" name="cookie"/><br/>
<input type="submit" value="登陸"/>
</form>
<?php 
	if(!empty($_GET['errNo'])){
		$errNo=$_GET['errNo'];
		echo "<br/><font color='red'>輸入的密碼或用戶名錯(cuò)誤,錯(cuò)誤信息</font>".$errNo;
	}
?>
</html>

  login.php中require_once的common.php

<?php
	function getLastTime(){
		date_default_timezone_set ( 'UTC' );
		if(!empty($_COOKIE)){
			echo "上次登錄時(shí)間:".$_COOKIE['last_visit_time'];
			setcookie("last_visit_time",date("Y-m-d  H:i:s"),time()+24*3600);
		}else{
			echo "第一次登錄";
			setcookie("last_visit_time",date("Y-m-d  H:i:s"),time()+24*3600);
		}
	}
	function getCookie($key){
		if(!empty($_COOKIE[$key])){
			return $_COOKIE[$key];
		}else{
			return "";
		}
	}
	function checkUserLegal(){
		session_start();
		if(empty($_SESSION['id'])){
			header("Location:login.php?errNo=1");
		}
	}
?>

  login.php中表單提交到loginProcess.php去。

<?php
	require_once 'adminService.class.php';
	if(!empty($_POST['cookie'])){			
		if(!empty($_POST['username'])){
		$username=$_POST['username'];
		setcookie("username","$username",time()+300);
		}	
		if(!empty($_POST['password'])){
		$password=$_POST['password'];
		setcookie("password","$password",time()+300);
		}
	}else{
		if(!empty($_POST['username'])){
			$username=$_POST['username'];
		}
		if(!empty($_POST['password'])){
			$password=$_POST['password'];
		}
	}
	$adminService=new adminService();
	
	
	if($id=$adminService->checkUser($username, $password)){
		//合法	
		session_start();
		$_SESSION['id']=$id;
		header("Location:Main.php?id=$id");
		exit();
		
	}else{
		//非法
		header("Location:login.php?errNo=2");
		exit();
	}
	

?>

  loginProcess中require_once的adminService.class.php。

<?php
	require_once 'SqlHelper.class.php';
	class adminService{
		//驗(yàn)證用戶是否合法
		public function checkUser($username,$password){
			$sqlHelper=new SqlHelper();
			$sql="select password,id from admin where name='".$username."'";
			
			$res=$sqlHelper->execute_dql($sql);

			if($row=mysql_fetch_assoc($res)){
				if($row['password']==md5($password)){
					$id=$row['id'];
					return $id;
				}else{
					return null;
				}
			}else{
					return null;
			}
			//釋放資源
			mysql_free_result($res);
			//關(guān)閉連接
			$sqlHelper->close_connent();
		}
			
	}
?>

  adminService.class.php中require_once的SqlHelper.class.php。

<?php
	class SqlHelper{
		public $conn;
		public $dbname="empmanage";
		public $host="localhost";
		public $username="root";
		public $password="root";
		public function __construct(){
			$conn=mysql_connect($this->host,$this->username,$this->password);
			if(!$conn){
				die("connect error".mysql_errno());
			}
			mysql_select_db($this->dbname) or die(mysql_errno());
			//mysql_query("set names utf8",$this->conn);
		}
		//dql
		public function execute_dql($sql){
			
			$res=mysql_query($sql) or die(mysql_error());
			
			return $res;
		}
		//dql2 返回一格數(shù)組 可以直接關(guān)閉結(jié)果集
		public function execute_dql2($sql){
			$arr=array();
			$i=0;
			$res=mysql_query($sql) or die(mysql_error());
			while($row=mysql_fetch_assoc($res)){
				$arr[$i++]=$row;
			}
			mysql_free_result($res);
			return $arr;
		}
		//分頁(yè)查詢
		public function execute_dql_fenye($sql1,$sql2,$fenyePage){
			$res=mysql_query($sql1) or die(mysql_error());
			$arr=array();
			while($row=mysql_fetch_assoc($res)){
				$arr[]=$row;
			}
			mysql_free_result($res);
			$fenyePage->res_array=$arr;
			
			$res2=mysql_query($sql2) or die(mysql_error());
			if($row=mysql_fetch_row($res2)){
				$fenyePage->rowCount=$row[0];
				$fenyePage->pageCount=ceil($row[0]/$fenyePage->pageSize);
			}
			mysql_free_result($res2);
			$daohangtiao="";
			if($fenyePage->pageNow>1){
				$prePage=$fenyePage->pageNow-1;
				$fenyePage->daohangtiao= "<a href='{$fenyePage->gotoUrl}?pageNow=$prePage'>上一頁(yè)</a>";
			}
			if($fenyePage->pageNow<$fenyePage->pageCount){
				$nextPage=$fenyePage->pageNow+1;
				$fenyePage->daohangtiao.= "<a href='{$fenyePage->gotoUrl}?pageNow=$nextPage'>下一頁(yè)</a>";
			}
			//用for打印10頁(yè)超鏈接
			$start=floor(($fenyePage->pageNow-1)/10)*10+1;
			$index=$start;
			if($fenyePage->pageNow>10){			
				$fenyePage->daohangtiao.= " <a href='{$fenyePage->gotoUrl}?pageNow=".($start-1)."'><<</a>";
			}
			for(;$start<$index+10;$start++){
				$fenyePage->daohangtiao.= "<a href='{$fenyePage->gotoUrl}?pageNow=$start'>[$start]</a>";
			}
				$fenyePage->daohangtiao.= " <a href='{$fenyePage->gotoUrl}?pageNow=$start'>>></a>";
				$fenyePage->daohangtiao.= " 當(dāng)前{$fenyePage->pageNow}頁(yè)/共{$fenyePage->pageCount}頁(yè)";
			
		}
		
		//dml
		public function execute_dml($sql){
			$res=mysql_query($sql) or die(mysql_error());
			if(!$res){
				return 0;//沒(méi)有用戶匹配
			}
			if(mysql_affected_rows($this->conn)>0){
				return 1;//ok
			}else{
				return 2;//沒(méi)有行受到影響
			}
		}
		//關(guān)閉連接
		public function close_connent(){
			if(!empty($this->conn)){
				mysql_close($this->conn);
			}
		}
	}	
?>

  驗(yàn)證是合法用戶跳轉(zhuǎn)到Main.php,非法跳轉(zhuǎn)到login.php并把errNo帶回去并用紅色輸出。如圖:

<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
</head>
<?php
	require_once 'common.php';
	checkUserLegal();
	
	$id=$_REQUEST['id'];
	echo "歡迎".$id."登陸";
// 	setcookie("last_visit_time","",time()-100);
	
	getLastTime();
?>
<h2>Main View</h2>
<a href="empList.php">管理用戶</a><br/>
<a href="addEmp.php">添加用戶</a><br/>
<a href="selectEmp.php">查詢用戶</a><br/>
</html>

php怎么實(shí)現(xiàn)簡(jiǎn)單的雇員管理系統(tǒng)

php怎么實(shí)現(xiàn)簡(jiǎn)單的雇員管理系統(tǒng)

  在Main頁(yè)面你可以選擇管理用戶,添加用戶,查詢用戶(用戶可以理解為雇員)。那么點(diǎn)擊查詢用戶后會(huì)跳轉(zhuǎn)到selectEmp.php去。

php怎么實(shí)現(xiàn)簡(jiǎn)單的雇員管理系統(tǒng)

<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
</head>
<h2>查找用戶</h2>
<form action="empProcess.php" method="post">
輸入id號(hào):<input type="text" name="id"/>
<input type="hidden" name="flag" value="selectEmp"/>
<input type="submit" value="go"/>
</form>
</html>

  在selectEmp.php中的表單會(huì)跳轉(zhuǎn)到empProcess.php去。

<?php
	require_once 'empService.class.php';
	require_once 'emp.class.php';
	$empService=new empService();
	if(!empty($_REQUEST['flag'])){
		
		if($_REQUEST['flag']=="del"){
			$id=$_REQUEST['id'];			
			if($empService->deleteById($id)==1){
				header("Location: ok.php");
				exit();
			}else{
				header("Location: err.php");
				exit();
			}
		
		}else if($_REQUEST['flag']=="addEmp"){
			$name=$_REQUEST['name'];
			$grade=$_REQUEST['grade'];
			$email=$_REQUEST['email'];
			$salary=$_REQUEST['salary'];
			if($empService->addEmp($name, $grade, $email, $salary)==1){
				header("Location: ok.php");
				exit();
			}else{
				header("Location: err.php");
				exit();
			}
		}else if($_REQUEST['flag']=="selectEmp"){
			$id=$_REQUEST['id'];			
			if($res=$empService->selectEmp($id)){
				echo "id{$res[0]['id']} name{$res[0]['name']} grade{$res[0]['grade']} email{$res[0]['email']} salary{$res[0]['salary']}";
			}
		}else if($_REQUEST['flag']=="updataEmp"){
			$id=$_REQUEST['id'];
			$name=$_REQUEST['name'];
			$grade=$_REQUEST['grade'];
			$email=$_REQUEST['email'];
			$salary=$_REQUEST['salary'];
			if($empService->updataEmp($id, $name, $grade, $email, $salary)==1){
				header("Location: ok.php");
				exit();
			}else{
					header("Location: err.php");
					exit();
			}
		}
	}
?>

  這其中require_once的empService.class.php和emp.class.php。

<?php
	require_once 'SqlHelper.class.php';
	class empService{
		
		
		//計(jì)算出$PageCount
		public function getPageCount($pageSize){
			$sqlHelper=new SqlHelper();
			$sql="select count(id) from emp";
			$res=$sqlHelper->execute_dql($sql);
			if($row=mysql_fetch_row($res)){
				$rowCount=$row[0];
			}
			$pageCount=ceil($rowCount/$pageSize);
			mysql_free_result($res);
			$sqlHelper->close_connent();
			return $pageCount;
		}
		//取出結(jié)果集
		public function getRes($pageNow,$pageSize){
			$sqlHelper=new SqlHelper();
			$sql="select id,name,grade,email,salary from emp limit ".($pageNow-1)*$pageSize.",$pageSize";
			$res=$sqlHelper->execute_dql2($sql);
 			$sqlHelper->close_connent();
			return $res;
		}
		//分頁(yè)
		public function getFenyePage($fenyePage){
			$sqlHelper=new SqlHelper();
			$sql1="select id,name,grade,email,salary from emp limit ".($fenyePage->pageNow-1)*$fenyePage->pageSize.",$fenyePage->pageSize";
			$sql2="select count(id) from emp";
			$sqlHelper->execute_dql_fenye($sql1, $sql2, $fenyePage);
			$sqlHelper->close_connent();
		}
		//刪除用戶
		public function deleteById($id){
			$sqlHelper=new SqlHelper();
			$sql="delete from emp where id=$id";
			return $sqlHelper->execute_dml($sql) or die(mysql_error());
			
			$sqlHelper->close_connent();	
		}
		//添加用戶
		public function addEmp($name,$grade,$email,$salary){
			$sqlHelper=new SqlHelper();
			$sql="insert into emp(name,grade,email,salary) values ('$name','$grade','$email','$salary')";
			
			return $sqlHelper->execute_dml($sql) or die(mysql_error());	
			$sqlHelper->close_connent();
		}
		//查詢用戶
		public function selectEmp($id){
			$sqlHelper=new SqlHelper();
			$sql="select * from emp where id=$id";
			$res=$sqlHelper->execute_dql2($sql) or die(mysql_error());
			$sqlHelper->close_connent();
			return $res;
		}
		//修改用戶
		public function updataEmp($id,$name,$grade,$email,$salary){
			$sqlHelper=new SqlHelper();
			$sql="update emp set name='$name',grade=$grade,email='$email',salary=$salary where id=$id";
			
			return $sqlHelper->execute_dml($sql) or die(mysql_error());
			$sqlHelper->close_connent();
		}
	}
?>
<?php
	class emp{
		public $res_arr_emp;
	}
?>

  驗(yàn)證后若該用戶存在輸出該用戶的詳細(xì)信息,如id name grade email salary。這是查詢,因?yàn)樽龅谋容^簡(jiǎn)單,所以沒(méi)有寫個(gè)超鏈接讓它返回上一層。

  若你在Main界面點(diǎn)擊的是添加用戶,則會(huì)跳轉(zhuǎn)到addEmp.php。

<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
</head>
<h2>添加用戶</h2>
<form action="empProcess.php" method="post">
<table>
<tr><td>name<td><td><input type="text" name="name"/><td></tr>
<tr><td>grade(tinyint)<td><td><input type="text" name="grade"/><td></tr>
<tr><td>email<td><td><input type="text" name="email"/><td></tr>
<tr><td>salary(int)<td><td><input type="text" name="salary"/><td></tr>
<tr><td><input type="submit" value="go"><td><td><input type="reset" value="reset"/><td></tr>
<tr><input type="hidden" name="flag" value="addEmp"></tr>
</table>
</form>
</html>

php怎么實(shí)現(xiàn)簡(jiǎn)單的雇員管理系統(tǒng)

  為了簡(jiǎn)單沒(méi)有用js正則表達(dá)式去對(duì)表單中所輸入的內(nèi)容進(jìn)行驗(yàn)證是否符合格式。輸入完表單后會(huì)跳轉(zhuǎn)到empProcess.php去驗(yàn)證。如果添加成功會(huì)跳轉(zhuǎn)到ok.php,否則會(huì)跳轉(zhuǎn)到err.php。

<?php
	header("Content-Type:text/html;charset=utf-8");
	echo "操作成功";
	echo "<a href=empList.php>返回上一級(jí)<a>";

?>
<?php
	header("Content-Type:text/html;charset=utf-8");
	echo "操作失敗<br/>";
	echo "<a href=empList.php>返回上一級(jí)<a>";
?>

  若在Main頁(yè)面點(diǎn)擊管理用戶則會(huì)跳轉(zhuǎn)到empList.php。

php怎么實(shí)現(xiàn)簡(jiǎn)單的雇員管理系統(tǒng)

<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
</head>
<?php
	require_once 'empService.class.php';	
	require_once 'FenyePage.class.php';
	require_once 'common.php';
	checkUserLegal();
	
	$fenyePage=new FenyePage();
	
	//分頁(yè)
	$fenyePage->pageNow=1;//顯示第幾頁(yè) 用戶輸入 不停變化
	if(!empty($_GET['pageNow'])){
		$fenyePage->pageNow=$_GET['pageNow'];
	}
	$fenyePage->pageCount=0;//共幾頁(yè) 需要$rowCount計(jì)算
	$fenyePage->pageSize=5;//一頁(yè)顯示多少條記錄
	$fenyePage->rowCount=0;//數(shù)據(jù)庫(kù)中獲取 共有幾條記錄
	$fenyePage->gotoUrl="empList.php";//要跳轉(zhuǎn)的頁(yè)面
	
	$empService=new empService();
	$empService->getFenyePage($fenyePage);
	echo "<table border='1px' >";
	echo "<tr><th>id</th><th>name</th><th>grade</th><th>email</th><th>salary</th><th><a href='#'>刪除用戶</a></th><th><a href='#'>修改用戶</a></th></tr>";
	for($i=0;$i<count($fenyePage->res_array);$i++){
		$row=$fenyePage->res_array[$i];
		
		echo "<tr><td>{$row['id']}</td><td>{$row['name']}</td><td>{$row['grade']}</td><td>{$row['email']}</td><td>{$row['salary']}</td><td><a href='empProcess.php?flag=del&id={$row['id']}'>刪除用戶</a></td><td><a href='updataEmp.php?flag=updataEmp&id={$row['id']}&name={$row['name']}&grade={$row['grade']}&email={$row['email']}&salary={$row['salary']}'>修改用戶</a></td></tr>";
	}
	echo "<table>";
	//打印導(dǎo)航條
	echo $fenyePage->daohangtiao;
	

?>
</html>

  其中require_once的FenyePage.class.php。

<?php
	class FenyePage{
		public $pageNow=1;//默認(rèn)打開(kāi)時(shí)第一頁(yè)
		public $pageSize;
		public $pageCount;
		public $rowCount;
		public $res_array;
		public $daohangtiao;//導(dǎo)航條
		public $gotoUrl;//要跳轉(zhuǎn)的頁(yè)面	
	}
?>

 點(diǎn)擊修改用戶會(huì)跳轉(zhuǎn)到updataEmp.php。

<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
</head>
<h2>修改用戶</h2>
<?php 
	
	if($_REQUEST['flag']=="updataEmp"){
		$id=$_REQUEST['id'];
		$name=$_REQUEST['name'];
		$grade=$_REQUEST['grade'];
		$email=$_REQUEST['email'];
		$salary=$_REQUEST['salary'];
	}
?>
<form action="empProcess.php" method="post">
<table>
<tr><td>id<td><td><input readonly="readonly" type="text" name="id" value="<?php echo $id;?>"/><td></tr>
<tr><td>name<td><td><input type="text" name="name" value="<?php echo $name;?>"/><td></tr>
<tr><td>grade(tinyint)<td><td><input type="text" name="grade" value="<?php echo $grade;?>"/><td></tr>
<tr><td>email<td><td><input type="text" name="email" value="<?php echo $email;?>"/><td></tr>
<tr><td>salary(int)<td><td><input type="text" name="salary" value="<?php echo $salary;?>"/><td></tr>
<tr><td><input type="submit" value="go"><td><td><input type="reset" value="reset"/><td></tr>
<tr><input type="hidden" name="flag" value="updataEmp"></tr>
</table>
</form>
</html>

php怎么實(shí)現(xiàn)簡(jiǎn)單的雇員管理系統(tǒng)

感謝各位的閱讀,以上就是“php怎么實(shí)現(xiàn)簡(jiǎn)單的雇員管理系統(tǒng)”的內(nèi)容了,經(jīng)過(guò)本文的學(xué)習(xí)后,相信大家對(duì)php怎么實(shí)現(xiàn)簡(jiǎn)單的雇員管理系統(tǒng)這一問(wèn)題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!

當(dāng)前題目:php怎么實(shí)現(xiàn)簡(jiǎn)單的雇員管理系統(tǒng)
文章URL:http://jinyejixie.com/article6/pgisog.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供做網(wǎng)站、外貿(mào)建站、網(wǎng)站維護(hù)營(yíng)銷型網(wǎng)站建設(shè)、網(wǎng)站營(yíng)銷、網(wǎng)站內(nèi)鏈

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都app開(kāi)發(fā)公司
安泽县| 北海市| 浦东新区| 湖州市| 正宁县| 铜川市| 天柱县| 弥勒县| 海口市| 台山市| 南丰县| 天祝| 噶尔县| 湘阴县| 宝清县| 铜川市| 大洼县| 增城市| 涞水县| 松江区| 武胜县| 稷山县| 靖边县| 兴隆县| 将乐县| 安阳市| 屏山县| 增城市| 许昌市| 民权县| 清水河县| 汪清县| 花莲市| 大兴区| 雷波县| 从化市| 汤原县| 都兰县| 平南县| 西城区| 合江县|