一个简单的注册页面(php+mysql)



   
       
       
   
   
       
       

           

Register


           

First Name:


               

Last Name:


                 

Eamil Address:


                     

Password:


                       

Confirm Password:


                       
       

                // require the connection file
        require('connect.php');
        //if posted
        if($_SERVER['REQUEST_METHOD']=='POST'){
            $errors=array();
     //check first name
            if(empty($_POST['fn'])){
                $errors[]='Please input your first name';
            }
            else{
                $fn=$_POST['fn'];
            }
                 //check last name
            if(empty($_POST['ln'])){
                $errors[]='Please input your last name';
            }
            else{
                $ln=$_POST['ln'];
            }
                          //check email address
            if(empty($_POST['email'])){
                $errors[]='Please input your email address';
            }
            else{
                $email=$_POST['email'];
            }
                                      //check password
            if(empty($_POST['ps1'])){
                $errors[]='Please input your password';
            }
            else{
                $ps1=$_POST['ps1'];
            }
     //confirm password
            if(empty($_POST['ps2'])){
                $errors[]='Please input your password again';
            }
            else{
                if($_POST['ps1']!=$_POST['ps2']){
                    $errors[]='Please confirm your password';
                }
                else{
               $p=$_POST['ps1'];         
                }
            
            }
            //Print errors when they exist
            if(!empty($errors)){
                echo"Error(s):";
                foreach($errors as $msg){
                    echo "

$msg

";
                }
            }
            else{
            //record the registration information
            $q="Insert into users(first_name,last_name,email,pass,registration_date)"
                    . "values('$fn','$ln','$email',MD5('$ps1'),now())";
            $r=mysqli_query($dbc,$q);
            if($r){
     echo"Registraion successed!";           
            }
            else{
                echo"Failed to register. Please check your information";
            }
        }
        }
        ?>
   

你可能感兴趣的:(一个简单的注册页面(php+mysql))