日期:2014-05-16 浏览次数:21089 次
环境 : 因为并不是真实搭建服务器,所以我偷懒用了phpstudy,集成了轻量版的apache,mysql和php. IDE采用Eclipse PHP Studio,毕竟用惯了Eclipse.
设置好apache本机目录(与EPS工程目录一致),使用phpMyAdmin添加测试用数据库fansdb,并建立新表test(含两个字段:user和password)
各网页源码:
//index.php 后台管理登陆:<br> <form action="login.php" method="post"> 姓名:<input type="text" name="name" /> 密码:<input type="text" name="password" /> <input type="submit" name="submit" value="提交" /> </form>
//login.php <?php require_once 'connectdb.php'; $name = $_POST['name']; $passowrd = $_POST['password']; $passowrd = md5($passowrd); if ($name && $passowrd){ $sql = "SELECT * FROM test WHERE user = '$name' and password='$passowrd'"; $res = mysql_query($sql); $rs=mysql_num_rows($res); if($rs){ header("refresh:0;url=userui.php"); exit; } else echo "<script language=javascript>alert('用户名密码错误');history.back();</script>"; }else { echo "<script language=javascript>alert('用户名密码不能为空');history.back();</script>"; } ?>
//userui.php <form action="" method="post"> <input type="submit" name="btn" value="列出所有"/> <input type="submit" name="btn" value="增加"/> <input type="submit" name="btn" value="删除"/> <input type="submit" name="btn" value="修改"/> <input type="submit" name="btn" value="查找"/> </form> <?php require_once 'controldb.php'; $action = $HTTP_POST_VARS["btn"]; switch($action){ case "列出所有": listuser(); break; case "增加": echo "<form action=\"\" method=\"post\"> 姓名:<input type=\"text\" name=\"name\" /> 密码:<input type=\"text\" name=\"password\" /> <input type=\"submit\" name=\"btn\" value=\"确定添加\"/> <br>"; break; case "删除": echo "<form action=\"\" method=\"post\"> 查找姓名:<input type=\"text\" name=\"name\" /> <input type=\"submit\" name=\"btn\" value=\"确定删除\"/> <br>"; break; case "修改": echo "<form action=\"\" method=\"post\"> 查找姓名:<input type=\"text\" name=\"name\" /> 修改后姓名:<input type=\"text\" name=\"dest_name\" /> 修改后密码:<input type=\"text\" name=\"dest_password\" /> <input type=\"submit\" name=\"btn\" value=\"确定修改\"/> <br>"; break; case "查找": echo "<form action=\"\" method=\"post\"> 查找姓名:<input type=\"text\" name=\"name\" /> <input type=\"submit\" name=\"btn\" value=\"确定查找\"/> <br>"; break; case "确定添加": if(add($_POST['name'],$_POST['password'])) echo "添加成功"; else echo "添加失败"; break; case "确定删除": if(del($_POST['name'])) echo "删除成功"; else echo "删除失败,可能不存在此人"; break; case "确定修改": if(change($_POST['name'],$_POST['dest_name'],$_POST['dest_password'])) echo "修改成