做为前台的注册用户可以查看修改自己的资料 这时候我们有关做个后台来管理用户数据 首前我们得建立一个admin表 [PHP] `id` int(11) NOT NULL auto_increment, `name` varchar(16) NOT NULL default '', `password` varchar(100) NOT NULL default '', `level` varchar(100) NOT NULL default '', `time` date NOT NULL default '0000-00-00', [/PHP] 字段 id 自动获取 字段 name 字段 password 字段 level 字段 time
照样的做个登陆的页面 POST数据提交 admin_man.php 检查正确不 然后在 开启SESSION [PHP] <html> <head> <title>管理员登陆</title> </head> <body topmargin="100" align="center" width="750"> <form method="post" action="admin_man.php"> <table align="center" cellspacing="0" sellspadding="0" border="0"> <tr><td align="center">管理员登陆</td></tr> <tr><td height="5"></td></tr> <tr><td>账 号:<Input type="text" name="name"></td></tr> <tr><td>密 码:<Input type="password" name="password"></td></tr> <tr><td height="5"></td></tr> <tr><td align="center"><Input type="submit" value="确 定"> <Input type="reset" value="取消"></td></tr> </table> </form> </body> </html> [/PHP] admin_man.php 一 检查是否为空 二 检查数据是否正确 [PHP] <?php session_start(); session_register("adname","adpass"); $name=$_POST['name']; $password=$_POST['password']; $_SESSION["adname"]=$name; $_SESSION["adpass"]=$password; $db1=php; if($name==''or$password==''){ echo"<script>alert('什么来的,输入了什么东西');location.href='admin_login.php';</script>"; } $conn=mysql_connect("localhost","root","root")or die("无法连接数据库"); $db=mysql_select_db($db,$conn) or die("无法连接PHP表"); $strsql="select * from admin where name='$name' and password='$password'"; $result=mysql_query($strsql,$conn); $num=mysql_fetch_object($result); $aname=$num->name; $apass=$num->password; if($name!=$aname){ echo "<script>alert('错误!检查用户名和密码');location.href='admin_login.php';</script>"; } elseif($password!=$apass){ echo"<script>alert('错误!检查用户名和密码');location.href='admin_login.php';</script>"; } else echo"<meta http-equiv=refresh content=0;URL=admin_main.php>"; /*这是 HTML里面的东西 上面的那些已经是多次解释了 不用解释了吧*/ ?> [/PHP] admin_main.php [PHP] <?php session_start(); if($_SESSION['adname']==''){ echo"<script>alert('请登陆后来管理');location.href='admin_login.php';</script>"; } else ?> <html> <head> <title>管理员控制版面</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> </head> <!-----------都是HTML代码 不用解释了吧----------> <frameset id="frame" cols="180,*" frameborder="NO" border="0" framespacing="0" rows="*"> <frame name="leftFrame" scrolling="AUTO" noresize src="admin_left.php" marginwidth="0" marginheight="0">
<frame name="main" src="admin_right.php" scrolling="AUTO" NORESIZE frameborder="0" marginwidth="10" marginheight="10" border="no">
</frameset> </frameset> <noframes>
</body></noframes> </html> [/PHP] 好了 看看 admin_left.php [PHP] <?php session_start(); if($_SESSION["adname"]==''){ echo"<script>alert('请登陆后来管理');location.href='admin_login.php';</script>"; } else $sqlname=$_SESSION["adname"]; include "config.php"; $strsql="select * from admin where name='$sqlname'"; $rresult=mysql_query($strsql,$conn)or die("无法执行操作"); $num=mysql_fetch_object($rresult); $name=$num->name; $password=$num->password; $level=$num->level; /*上面这些东西不用解释了吧*/ ?> <html> <head></head> <body> <table width="100%" cellspacing="0" cellspadding="0" border="0"> <tr><td align="center" width="100%" bgcolor="#AD4207"><font color="#FFFFFF">欢迎<?php echo $sqlname;?>进入</font></td></tr> <tr><td height=5></td></tr> <tr><td align="center" width="100%" bgcolor="#AD4207"><font color="#FFFFFF">系统控制</font></td></tr> <tr><td height=1 bgcolor=#000000></td></tr> <tr><td align="center"><a href="php.php" target=main>系统信息</a></td></tr> <tr><td align="center"><a href="system.php" target=main>常规设置</a></td></tr> <tr><td align="center"><a href="readme.php" target=main>相关说明</a></td></tr> <tr><td align="center" width="100%" bgcolor="#AD4207"><font color="#FFFFFF">管理员控制</font></td></tr> <tr><td height=1 bgcolor=#000000></td></tr> <?php echo "<tr><td align='center'><a href='admin_pass.php?'.SID.'' target=main>修改密码</a></td></tr>" /*这个后面为什么要加个'.SID.'了 我只知道 如果新开起一个窗口 传递SESSION值得不加个'.SID.'就不能传递*/ ?> <?php if($level=='1'){ echo "<tr><td align='center'><a href='admin_add.php?'.SID.'' target=main>添加管理员</a></td></tr>"; } else ?> <?php if($level=='1'){ echo "<tr><td align='center'><a href='admin_set.php?'.SID.'' target=main>调整管理员</a></td></tr>"; } else ?> <tr><td align="center" width="100%" bgcolor="#AD4207"><font color="#FFFFFF">用户管理</font></td></tr> <tr><td height=1 bgcolor=#000000></td></tr> <?php echo"<tr><td align='center'><a href='admin_user.php?'.SID.'' target=main>查看所有用户</a></td></tr>" ?> <tr><td align="center"><a href="readme.php" target=main>查找用户</a></td></tr> <?php if($level=='1'){ echo "<tr><td align='center'><a href='readme.php?'.SID.'' target=main>编辑用户</a></td></tr>"; } else ?> </table> </body> </html> [/PHP] 下面在讲一下 关于删除 和分页列表出来 基本上其他的 可以自己做的出来了 
|