Home > Backend Development > PHP Tutorial > PHP code example for user registration

PHP code example for user registration

WBOY
Release: 2016-07-25 08:58:20
Original
1370 people have browsed it
This article introduces an example of user registration information detection and storage implemented in PHP. Friends in need can refer to it.

The code is as follows:

<?
/**
* 用户注册示例
* edit bbs.it-home.org
*/
php session_start();
$conn=mysqli_connect("localhost","root","root","reguser");
$conn->query('set names gb2312');
if(empty($conn))
{
   die("数据库连接失败");
}
$UserName=$_POST['username'];
$pwd=$_POST['password'];
$email=$_POST['email'];
$sex=$_POST['sex'];
$time=time();
$code=strtolower($_POST["code"]);
$str="select * from users where username='".$username."'";
   $result1=$conn->query($str);
   $row=$result1->fetch_row();
if($row)
{ 
$temp="已有人注册此名,请重新选择名字!"; 
echo $temp;
echo"返回";
} 
else {
if( $_SESSION['sname']==$code)
{
   echo $temp="认证码成功";
   $sql="INSERT INTO users VALUES('$username', '$password','$email','$sex','$time')";
   $result=$conn->query($sql);
   if($result==true)
      {
      $_SESSION['mail']="注册成功,请登陆";
      echo "";
      }
      else {echo "注册失败".mysql_error();}
} 
else {echo "认证码错误";}
}
?>
Copy after login

The above code receives parameters from the registration page, including username, password, email, gender, verification code, etc. Then, check whether it has been registered, otherwise the registration information will be written to the database. It's very simple, especially suitable for novice friends to refer to.



source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template