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

PHP user development registration module PHP page

The main functions of user registration were introduced earlier. This page implements these functions through PHP code.

We use POST method to obtain data.

<?php
$username = $_POST['username']; //注冊的用戶名
$password = $_POST['password'];  //注冊密碼
$confirm = $_POST['confirm'];  //確認(rèn)密碼
$email = $_POST['email'];  //郵箱
$code = $_POST['code'];   //驗證碼
?>

Continue to connect to the database and table we have created

<?php
$link = mysqli_connect('localhost','root','root','test');
if (!$link) {
  die("連接失敗:".mysqli_connect_error());
}
$sql = "select * from login";
$result = mysqli_query($link, $sql);
$rows = mysqli_fetch_array($result);
?>

We need to make regular judgments on the entered user name and email address

<?php
if ((strlen($username) < 3)||(!preg_match('/^\w+$/i', $username))) 
{  
     echo "<script>alert('用戶名至少3位且不含非法字符!重新填寫');window.location.href='zhuce'</script>";  
     //判斷用戶名長度和非法字符
}
if (!preg_match('/^[\w\.]+@\w+\.\w+$/i', $email)) 
{    
     echo "<script>alert('郵箱不合法!重新填寫');window.location.href='zhuce.html'</script>";    
     //判斷郵箱格式是否合法
}
?>

The biggest difference here from user login is if The username has been registered by another user and you will no longer be able to use this username.

You need to read the username data that already exists in the database first, and then make a judgment.

<?php
if(mysqli_fetch_array(mysqli_query($link,"select * from login where username = '$username'")))
{     
    echo "<script>alert('用戶名已存在');window.location.href='zhuce.html'</script>";
    // 判斷用戶名是否已經(jīng)被注冊
}
?>

Complete zhuce.php file code:

<?php
  session_start();
  header("Content-type:text/html;charset=utf-8");
  $link = mysqli_connect('localhost','root','root','test');
  if (!$link) {
    die("連接失敗:".mysqli_connect_error());
  }
  
  $username = $_POST['username'];
  $password = $_POST['password'];
  $confirm = $_POST['confirm'];
  $email = $_POST['email'];
  $code = $_POST['code'];
  
  if($username == "" || $password == "" || $confirm == "" || $email == "" || $code == "")
  {
    echo "<script>alert('信息不能為空!重新填寫');window.location.href='zhuce.html'</script>";
  } elseif ((strlen($username) < 3)||(!preg_match('/^\w+$/i', $username))) {
    echo "<script>alert('用戶名至少3位且不含非法字符!重新填寫');window.location.href='zhuce'</script>";
    //判斷用戶名長度
  }elseif(strlen($password) < 5){
      echo "<script>alert('密碼至少5位!重新填寫');window.location.href='zhuce.html'</script>";
      //判斷密碼長度
  }elseif($password != $confirm) {
      echo "<script>alert('兩次密碼不相同!重新填寫');window.location.href='zhuce.html'</script>";
      //檢測兩次輸入密碼是否相同
  } elseif (!preg_match('/^[\w\.]+@\w+\.\w+$/i', $email)) {
      echo "<script>alert('郵箱不合法!重新填寫');window.location.href='zhuce.html'</script>";
      //判斷郵箱格式是否合法
  } elseif($code != $_SESSION['authcode']) {
    echo "<script>alert('驗證碼錯誤!重新填寫');window.location.href='zhuce.html'</script>";
    //判斷驗證碼是否填寫正確
  } elseif(mysqli_fetch_array(mysqli_query($link,"select * from login where username = '$username'"))){
    echo "<script>alert('用戶名已存在');window.location.href='zhuce.html'</script>";
  } else{
    $sql= "insert into login(username, password, confirm, email)values('$username','$password','$confirm','$email')";
    //插入數(shù)據(jù)庫
    if(!(mysqli_query($link,$sql))){
      echo "<script>alert('數(shù)據(jù)插入失敗');window.location.href='zhuce.html'</script>";
    }else{
      echo "<script>alert('注冊成功!)</script>";
    }
  }
?>

Enter the registration page, fill in all the correct data, and then open the database and you will find that the data you just added already exists.

2.png

For example: Here we add a user with a username of sell, password and confirmation password of 12345, and an email address of 123@www.com.

Note: This course only briefly demonstrates user registration. Its code is for learning reference only and cannot be used directly in projects.

Continuing Learning
||
<?php session_start(); header("Content-type:text/html;charset=utf-8"); $link = mysqli_connect('localhost','root','root','test'); if (!$link) { die("連接失敗:".mysqli_connect_error()); } $username = $_POST['username']; $password = $_POST['password']; $confirm = $_POST['confirm']; $email = $_POST['email']; $code = $_POST['code']; if($username == "" || $password == "" || $confirm == "" || $email == "" || $code == "") { echo "<script>alert('信息不能為空!重新填寫');window.location.href='zhuce.html'</script>"; } elseif ((strlen($username) < 3)||(!preg_match('/^\w+$/i', $username))) { echo "<script>alert('用戶名至少3位且不含非法字符!重新填寫');window.location.href='zhuce'</script>"; //判斷用戶名長度 }elseif(strlen($password) < 5){ echo "<script>alert('密碼至少5位!重新填寫');window.location.href='zhuce.html'</script>"; //判斷密碼長度 }elseif($password != $confirm) { echo "<script>alert('兩次密碼不相同!重新填寫');window.location.href='zhuce.html'</script>"; //檢測兩次輸入密碼是否相同 } elseif (!preg_match('/^[\w\.]+@\w+\.\w+$/i', $email)) { echo "<script>alert('郵箱不合法!重新填寫');window.location.href='zhuce.html'</script>"; //判斷郵箱格式是否合法 } elseif($code != $_SESSION['authcode']) { echo "<script>alert('驗證碼錯誤!重新填寫');window.location.href='zhuce.html'</script>"; //判斷驗證碼是否填寫正確 } elseif(mysqli_fetch_array(mysqli_query($link,"select * from login where username = '$username'"))){ echo "<script>alert('用戶名已存在');window.location.href='zhuce.html'</script>"; } else{ $sql= "insert into login(username, password, confirm, email)values('$username','$password','$confirm','$email')"; //插入數(shù)據(jù)庫 if(!(mysqli_query($link,$sql))){ echo "<script>alert('數(shù)據(jù)插入失敗');window.location.href='zhuce.html'</script>"; }else{ echo "<script>alert('注冊成功!)</script>"; } } ?>
submitReset Code