亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

PHP development corporate website tutorial - adding administrators

In the previous section we have taken out the information from the database and displayed the display page

As you can see from the code in the previous section, we click to add an administrator and submit it to the addu.php page

Let’s take a look at the code of this page

<!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>
        密&nbsp;碼:<input type="password" name="password" class="ipt"></br></br>
        <input type="submit" value="添加" class="sub">
    </form>
</body>
</html>

Looking at the above code, we can see that the form is submitted to the adduser.php file in the form of post

Let’s do this Take a look at the code of the adduser.php file, and then analyze the code:

<?php
    //添加管理員部分代碼,注意,當(dāng)數(shù)據(jù)庫存在該管理員賬戶時,不允許添加
    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>";
        }
    }
?>

First we also need to connect to the database, and then receive the information submitted by the form

After that we need to judge the form submission Does the user exist? If it exists, a prompt will be given. If it does not exist, you can add it

As shown in the above code, in this way we have completed the function added by the administrator

Continuing Learning
||
<!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>
submitReset Code