<?
error_reporting(0);
include("../../include/common.php");
$action=addslashes($_GET["action"]);
$id=intval($_GET["id"]);

if($action=="add")
{
	$username=addslashes($_POST["username"]);
	
	$password=md5(addslashes($_POST["password"]));
	
	if($username=="" && $password=="")
	{
		die("填写详细");
	}
	
	$rows=$mysql->rownums("select * from userinfo where username='$username'");
	
	if($rows>=1)
	{
		die("貌似有重复的用户名,换一个试试吧");
	}
	
	$sql="insert into userinfo (username,password) value ('$username','$password')";
	
	//echo $sql;
	
	$mysql->query($sql);
	
	redirect();
}

if($action=="edit")
{	
	$password=md5(addslashes($_POST["password"]));
	
	if($password=="")
	{
		die("密码忘写了吧");
	}
	
	$sql="update userinfo set password='$password' where id=$id";
	
	$mysql->query($sql);
	
	redirect();
	
}

if($action=="del")
{
	$rows=$mysql->rownums("select * from userinfo");
	if($rows==1)
	{
		die("您得至少保证有一个用户吧");
	}
	$mysql->query("delete from userinfo where id=$id");
	redirect();
}
?>