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

Registration function (2)

The front-end page of the registration page has been completed. Let’s talk about the background program code.

First of all, we need to know that the registration function is actually the process of adding data to the database. To add data to the database, you must first connect to the database. There is no doubt about this. Then, you must obtain the registration information passed from the front-end page in the background. We only have user name and password here. You can add them as needed in actual projects in the future. Database fields. After obtaining the value passed by the form, use the SQL statement to write an add statement to add the obtained value to the database. In this way, our entire registration process is almost complete. Let's take a closer look at the code.

Step 1: Connect to the database

<?php
header("content-type:text/html;charset=utf-8");
//連接數(shù)據(jù)庫
$link = mysqli_connect("localhost","root","root","joke");
if (!$link) {
    die("連接失敗: " . mysqli_connect_error());
}

Step 2: Get the value passed by the form

<?php
$username=$_POST['username'];
$password=$_POST['password'];
?>

Let me tell you here that the registration function does not allow direct submission without filling in the value Yes, it cannot be empty and must be filled, so

Step 3: Verify that the information is complete and write the insertion statement:

<?php
if($username == "" || $password == "")  //判斷前端頁面?zhèn)鬟f的值是不是完整
{
   echo "請確認(rèn)信息完整性";
}else{
       $sql="insert into login(username,password) values('$username','$password')";  //完整的話講傳遞過來的數(shù)據(jù)插入數(shù)據(jù)庫
       $result=mysqli_query($link,$sql);         //執(zhí)行操作,將返回的結(jié)果賦值給變量$result
       if(!$result)                               //判斷$result有沒有值,如果有就添加成功,跳轉(zhuǎn)至登錄頁面;如果沒有值,說明添加失敗,返回注冊頁面
       {
           echo"注冊不成功!"."<br/><br/>";
           echo"<a href='resgiter.html'>返回</a>";
       }
       else
       {
           echo"注冊成功!"."<br/><br/>";
           echo"<a href='login.html'>立刻登錄</a>";
       }
   }

The above are the steps to register the function.

Continuing Learning
||
<?php header("content-type:text/html;charset=utf-8"); //連接數(shù)據(jù)庫 $link = mysqli_connect("localhost","root","root","joke"); if (!$link) { die("連接失敗: " . mysqli_connect_error()); } $username=$_POST['username']; $password=$_POST['password']; if($username == "" || $password == "") { echo "請確認(rèn)信息完整性"; }else{ $sql="insert into login(username,password) values('$username','$password')"; $result=mysqli_query($link,$sql); if(!$result) { echo"注冊不成功!"."<br/><br/>"; echo"<a href='resgiter.html'>返回</a>"; } else { echo"注冊成功!"."<br/><br/>"; echo"<a href='login.html'>立刻登錄</a>"; } }
submitReset Code