Registration background ideas and code for PHP development

The front end is all prepared and produced, now we will use PHP to implement these functions.

First of all, let’s sort out our ideas. We can clearly see our overall idea through the following flow chart:

39C.tmp.jpg

<?php
header("content-type:text/html;charset=utf-8");
//连接数据库
$link = mysqli_connect("localhost","root","root","regedit");
if (!$link) {
    die("连接失败: " . mysqli_connect_error());
}

$username=$_POST['username'];
$password=$_POST['password'];
$pwd_again=$_POST['pwd_again'];
if($username == "" || $password == "" || $pwd_again == "")
{
    echo "请确认信息完整性";
}else{
    if($password!=$pwd_again)
    {
        echo"两次输入的密码不一致,请重新输入!"."<br/><br/>";
        echo"<a href='regedit.html'>重新输入</a>";
    }
    else
    {
        $sql="insert into form(username,password) values('$username','$password')";
        $result=mysqli_query($link,$sql);
        if(!$result)                                               // 判断数据是否成功插入进数据库
        {
            echo"注册不成功!"."<br/><br/>";
            echo"<a href='regedit.html'>返回</a>";
        }
        else
        {
            echo"注册成功!"."<br/><br/>";
            echo"<a href='login.html'>立刻登录</a>";
        }
    }
}
?>

First of all, because we need to The data is transferred into the database, so you must first connect to the database

and then verify the data filled in during registration to determine whether the two passwords are the same and whether the registration information is completed. If it is incomplete or different, register fail.

Finally, use the database insert statement to add the registration content to the database to determine whether the addition is successful. If the addition fails, the registration fails, otherwise it is successful.


Continuing Learning
||
<?php header("content-type:text/html;charset=utf-8"); //连接数据库 $link = mysqli_connect("localhost","root","root","regedit"); if (!$link) { die("连接失败: " . mysqli_connect_error()); } $username=$_POST['username']; $password=$_POST['password']; $pwd_again=$_POST['pwd_again']; if($username == "" || $password == "" || $pwd_again == "") { echo "请确认信息完整性"; }else{ if($password!=$pwd_again) { echo"两次输入的密码不一致,请重新输入!"."<br/><br/>"; echo"<a href='regedit.html'>重新输入</a>"; } else { $sql="insert into form(username,password) values('$username','$password')"; $result=mysqli_query($link,$sql); if(!$result) // 判断数据是否成功插入进数据库 { echo"注册不成功!"."<br/><br/>"; echo"<a href='regedit.html'>返回</a>"; } else { echo"注册成功!"."<br/><br/>"; echo"<a href='login.html'>立刻登录</a>"; } } } ?>
submitReset Code