<?php
session_start();
//Registration processing interface regcheck.php
if(isset($_POST["hidden"]) && $_POST["hidden"] == "hidden")
{
$user = trim($_POST["username"]);//trim() function removes strings White space characters on both sides
$psw = md5(trim($_POST["userpwd"]));
$psw_confirm = md5(trim($_POST["confirm"])) ;
$code = $_POST["code"];
if($user == "" || $psw == "" || $psw_confirm == "")
{
echo "<script>alert('Please confirm the integrity of the information!'); history.go(-1);</script>";
}
else if($code != $_SESSION[' ver_code']){
echo "<script>alert('The verification code is incorrect, please re-enter!') ; history.go(-1);</script>";
}
else
{
if($psw == $ psw_confirm)
{
$conn = mysqli_connect("localhost","root","root"); //Connect to the database, the account password is the account password of your own database
if(mysqli_errno($conn)){
echo mysqli_error($conn);
exit;
}
mysqli_select_db($conn, "userdb"); //Select database
mysqli_set_charset($conn,'utf8'); //Set character set
$sql = "select username from user where username = '$ user'"; //SQL statement
$result = mysqli_query($conn,$sql); //Execute SQL statement
$num = mysqli_num_rows($result); //Statistical execution The number of rows affected by the result
if($num) //If the user already exists
{
echo "<script>alert( 'Username already exists'); history.go(-1);</script>";
}
else //The current registered user name does not exist
{
$ip=ip2long($_SERVER['REMOTE_ADDR']); // Convert the ip address into an integer
$time=time();
$sql_insert = "insert into `user` (`username`,`userpwd`,`createtime`,`createip`) values('" . $user . "','" . $psw ."','".$ time."','".$ip."')";
$res_insert = mysqli_query($conn,$sql_insert);
if($res_insert)
{
echo "<script>alert('Registration successful! ');window.location.href='login.php';</script>";
}
else
{
echo "<script>alert('The system is busy, please wait!'); history.go(-1);</script>";
}
}
}
else
{
echo "<script>alert('Password inconsistent!'); history.go( -1);</script>";
}
}
}
else
{
echo "<script>alert('Submission failed!');</script>";
}
?>
Print $code and $_SESSION[' ver_code'] respectively to see if there is any data