empList.php
<html><head><meta content="text/html;charset=utf-8" http-equiv="content-type"><title>僱員資訊列表</title></head><?php$conn = mysql_connect ( "localhost", "root", "root" ) or die ( mysql_error () );mysql_query ( "set names utf8" );//選擇資料庫mysql_select_db ( "test", $conn );$pageSize=3;//每頁數$rowCount=0;//記錄數$pageNow=1;//當前頁$pageCount=0;//頁數 //根據使用者的點擊收取pagenow的值if(!empty($_GET['pageNow'])){$pageNow=$_GET['pageNow'];}$sql="select count(id) from emp";;$res1=mysql_query($sql);//取出記錄數if($row=mysql_fetch_row($res1)){$rowCount=$row[0];}//計算共有多少頁$pageCount=ceil($rowCount/$pageSize);$sql = "select * from emp limit ".($pageNow-1)*$pageSize.",$pageSize";$res2 = mysql_query ( $sql, $conn );echo "<table width='700px' border='1px'>";echo "<tr><th>id</th><th>name</th><th>grade</th>";echo "<th>email</th><th>salary</th><td colspan='2'>操作</td></tr>";//這裡我們需要迴圈顯示使用者的資訊while ( $row = mysql_fetch_assoc ( $res2 ) ) {echo "<tr><td>{$row['id']}</td><td>{$row['name']}</td><td>{$row['grade']}</td>";echo "<td>{$row['email']}</td><td>{$row['salary']}</td>";echo "<td><a href='#'>刪除使用者</a></td>";echo "<td><a href='#'>修改使用者</a></td><tr>";}echo "<h1>僱員資訊列表</h1>";echo "<hr/>";echo "</table>";//列印頁碼的超連結for ($i = 1; $i <= $pageCount; $i++) {echo "<a href='empList.php?pageNow=$i'>$i</a> ";}//關閉資源mysql_free_result($res2);mysql_close($conn);?></html>
empManage.php
<html><head><meta http-equiv="content-type" content="text/html;charset=utf-8"></head><?phpecho "歡迎你," . $_GET ['name'] . "登入成功!...";echo "<br/><a href='login.php'>返回重新登入</a>";?><h1>主介面</h1><a href="empList.php">系統管理使用者</a><br /><a href="#">添加使用者</a><br /><a href="#">查詢使用者</a><br /><a href="#">退出系統</a><br /></html>
loginProcess.php
<?php//接受使用者的資料//1.id$id = $_POST ['id'];//2.密碼$password = $_POST ['password'];//得到串連$conn = mysql_connect ( "localhost", "root", "root" );if (! $conn) {die ( "串連失敗" . mysql_errno () );}//設定訪問資料庫的編碼mysql_query ( "set names utf8", $conn ) or die ( mysql_errno () );//選擇資料庫mysql_select_db ( "test", $conn ) or die ( mysql_errno () );//發送sql語句驗證$sql = "select password,name from admin where id=$id";//通過id擷取password$res = mysql_query ( $sql, $conn );if ($row = mysql_fetch_assoc ( $res )) {//取出資料庫的密碼if ($row ['password'] == md5 ( $password )) {//合法//取出使用者名稱字$name=$row['name'];header ( "Location:empManage.php?name=$name" );exit ();}}header ( "Location:login.php?errno=1" );exit ();//關閉資源mysql_free_result($res);mysql_close($conn);?>
login.php
<html><head><meta content="text/html;charset=utf-8" http-equiv="content-type"></head><h1>管理員登入系統</h1><form action="loginProcess.php" method="post"><table><tr><td>使用者id</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></table></form><?php if(!empty($_GET['errno'])){ $errno=$_GET['errno']; if($errno==1){ echo "<font color='red' size='3'>你的使用者名稱或密碼錯誤</font>"; }} ?></html>