我(wǒ)(wǒ)自做的一(yī)個簡單的用戶添加與管理程序

發布時間:2007年01月26日      浏覽次數:2407 次
add.php
======================================================================
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<table border="0" cellspacing="0" cellpadding="4">
<tr>
<td><a href="index.php">首頁</a></td>
<td><a href="add.php">添加管理員(yuán)</a></td>
<td> </td>
<td> </td>
</tr>
</table>
<form name="form1" method="post" action="add.php">
<table width="400" border="1" align="center" cellpadding="4" cellspacing="0" bordercolor="#CCCCCC" bordercolordark="#FFFFFF">
<tr bgcolor="#CCCCCC">
<td colspan="2"><div align="center">添加管理員(yuán)</div></td>
</tr>
<tr>
<td width="122" nowrap><div align="right">管理員(yuán)帳号:</div></td>
<td width="256"><input name="adminname" type="text" id="adminname" maxlength="20"></td>
</tr>
<tr>
<td nowrap><div align="right">管理員(yuán)密碼:</div></td>
<td><input name="adminpwd" type="password" id="adminpwd" maxlength="50"></td>
</tr>
<tr>
<td nowrap><div align="right">重複密碼:</div></td>
<td><input name="repwd" type="password" id="repwd" maxlength="50"></td>
</tr>
<tr>
<td nowrap><div align="right">管理員(yuán)名稱:</div></td>
<td><input name="uname" type="text" id="uname" maxlength="10"></td>
</tr>
<tr>
<td nowrap><div align="right">管理員(yuán)級别:</div></td>
<td><select name="user_level">
<option value="超級管理員(yuán)">超級管理員(yuán)</option>
<option value="普通管理員(yuán)" selected>普通管理員(yuán)</option>
</select></td>
</tr>
<tr>
<td colspan="2"><div align="center">
<input type="submit" name="Submit" value="提交">
</div></td>
</tr>
</table>
</form>
<?php
//包含數據庫鏈接文件
include "conn.php";
//接收表單提交的數據
if (isset($_POST["Submit"]))
{
      if (isset($_POST["adminname"]))$adminname=$_POST["adminname"];
      if (isset($_POST["adminpwd"]))$adminpwd=$_POST["adminpwd"];
      if (isset($_POST["repwd"]))$repwd=$_POST["repwd"];
      if (isset($_POST["uname"]))$uname=$_POST["uname"];
      if (isset($_POST["user_level"]))$user_level=$_POST["user_level"];
      
      //判斷表單值是否合法
      if ($adminname=="")
      {
            echo("<script language=javascript>alert(\"請輸入管理員(yuán)帳号!\");history.go(-1);</script>");
            exit();
      }
      if ($adminpwd=="")
      {
            echo("<script language=javascript>alert(\"請輸入管理員(yuán)密碼!\");history.go(-1);</script>");
            exit();
      }
      if ($adminname<>$repwd)
      {
            echo("<script language=javascript>alert(\"兩次輸入密碼不一(yī)緻,請重新輸入!\");history.go(-1);</script>");
            exit();
      }
      if ($uname=="")
      {
            echo("<script language=javascript>alert(\"請輸入管理員(yuán)名稱!\");history.go(-1);</script>");
            exit();
      }
      //添加數據到數據庫
      if ($adminname<>"" and $adminpwd<>"")
      {
            $rs=$conn->execute("insert into ad_admin(adminname,adminpwd,uname,user_level) values('$adminname','$adminpwd','$uname','$user_level')");
            echo ("管理員(yuán) $adminname 添加成功!");
      }
      
}
?>
============================================================================
index.php
=============================================================================
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<table border="0" cellspacing="0" cellpadding="4">
<tr>
<td><a href="index.php">首頁</a></td>
<td><a href="add.php">添加管理員(yuán)</a></td>
<td> </td>
<td> </td>
</tr>
</table>
<table width="100%" border="1" cellpadding="2" cellspacing="0" bordercolor="#CCCCCC" bordercolordark="#FFFFFF">
<tr bgcolor="#CCCCCC">
<td nowrap><div align="center">編号</div></td>
<td nowrap><div align="center">帳号</div></td>
<td nowrap><div align="center">名稱</div></td>
<td nowrap><div align="center">級别</div></td>
<td nowrap><div align="center">添加時間</div></td>
</tr>
<?php
//包含數據庫鏈接文件
include "conn.php";
//查詢數據庫,顯示數據
$rs=$conn->execute("select * from ad_admin");
$i=0;
if (!$rs->eof and !$rs->bof)
{
      while (!$rs->eof and !$rs->bof){
      ?>
<tr>
<td> <?php echo $rs["id"] ?> </td>
<td> <?php echo $rs["adminname"] ?> </td>
<td> <?php echo $rs["uname"] ?> </td>
<td> <?php echo $rs["user_level"] ?> </td>
<td> <?php echo $rs["sj"] ?> </td>
</tr>
<?php
      $i+=1;
      $rs->movenext();
      }
}
$rs->close();
?>
</table>
================================================================
conn.php
================================================================
<?php
$conn=new com("adodb.connection");
$conn->open("driver=microsoft access driver (*.mdb);dbq=ad.mdb");
?>
免責聲明:本站相關技術文章信息部分(fēn)來自網絡,目的主要是傳播更多信息,如果您認爲本站的某些信息侵犯了您的版權,請與我(wǒ)(wǒ)們聯系,我(wǒ)(wǒ)們會即時妥善的處理,謝謝合作!