PHP ?? ?? ???? ???? - ??? ??
??? ????? ???????? ??? ??? ?? ???? ??????.
?? ??? ???? ? ? ??? ???? ????? ???? addu.php ???? ?????
? ???? ???? ??
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>添加管理員</title> <style type="text/css"> .ipt{width:180px;height:30px;border-radius:5px; outline:none;border:1px solid #eee;box-sizing:border-box;padding-left:15px;} .sub{width:50px;height:20px;border:1px solid #eee;background:#eee;color:#ff7575;} </style> </head> <body> <form method="post" action="adduser.php"> 用戶名:<input type="username" name="username" class="ipt"></br></br> 密 碼:<input type="password" name="password" class="ipt"></br></br> <input type="submit" value="添加" class="sub"> </form> </body> </html>
? ??? ?? adduser.php ??? ??? ??? ?? ???? ?? ? ? ??
??? ??? ???? adduser.php ??? ?? ?? ??? ?????:
<?php //添加管理員部分代碼,注意,當(dāng)數(shù)據(jù)庫存在該管理員賬戶時(shí),不允許添加 require_once('conn.php'); $name = $_POST['username']; $password = md5($_POST['password']); $sql1 = "select * from user where username ='$name'"; $info = mysql_query($sql1); $res1 = mysql_num_rows($info); if($res1){ echo "<script>alert('管理員已存在');location.href='addu.php';</script>"; }else{ $sql = "insert into `user`(username,password) values('$name','$password')"; $res = mysql_query($sql); if($res){ echo "<script>alert('添加管理員成功');location.href='user.php';</script>"; }else{ echo "<script>alert('添加管理員失敗');history.go(-1);</script>"; } } ?>
?? ??????? ??? ?? ???? ??? ??? ??? ???.
? ???? ??? ??? ???? ???? ???? ???. ????? ????? ??, ???? ???? ???? ???
? ??? ?? ???? ??? ??? ???????