<?php
session_start();
header("Content-type:text/html;charset=utf-8");
$link = mysqli_connect('localhost','000000','000000','000000');
if (!$link) {
die("Connection failed:".mysqli_connect_error() );
}
$sql = "select * from login";
$result = mysqli_query($link, $sql);
$ rows = mysqli_fetch_array($result);
$username = $_POST['username'];
$password = $_POST['password'];
$confirm = $_POST['confirm'];
$email = $_POST['email'];
if($username == "" || $password == "" || $confirm == "" || $email == "")
if ((strlen($username) < 3)||(!preg_match ('/^\w $/i', $username)))
{
echo "<script>alert('The information cannot be empty! Refill');window. location.href='zhuce.html'</script>";
} elseif ((strlen($username) < 3)||(!preg_match('/^\w $/i' , $username))) {
echo "<script>alert('Username must be at least 3 digits and does not contain illegal characters! Refill it');window.location.href='zhuce'</ script>";
//Determine the length of the username
}elseif(strlen($password) < 5){
echo "<script>alert(' The password must be at least 5 digits! Refill');window.location.href='zhuce.html'</script>";
//Judge password length
}elseif($password != $confirm) {
echo "<script>alert('The two passwords are different! Refill');window.location.href='zhuce.html'</script>";
//Check whether the password entered twice is the same
} elseif (!preg_match('/^[\w\.] @\w \.\w $/i', $email))
echo "<script>alert('The email is illegal! Refill');window.location.href='zhuce.html'</script>";
//Determine the email format Is it legal
elseif(mysqli_fetch_array(mysqli_query($link,"select * from login where username = '$username'"))){
echo "<script>alert('User name already exists');window.location.href='zhuce.html'</script>";
} else{
$sql= "insert into login(username, password , confirm, email)values('$username','$password','$confirm','$email')";
//Insert into the database
if(!(mysqli_query ($link,$sql))){
echo "<script>alert('Data insertion failed');";
}else{
echo "<script>alert('Registration successful');window.location.href='yonghu.html'</script>";
}
}
?>