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:
<?php header("content-type:text/html;charset=utf-8"); //連接數(shù)據(jù)庫 $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 "請確認(rèn)信息完整性"; }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) // 判斷數(shù)據(jù)是否成功插入進(jìn)數(shù)據(jù)庫 { 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.