Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.27 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. echo "<h1>Register</h1>";
  5.  
  6. $submit = $_POST['submit'];
  7.  
  8. //form data
  9. $fullname = strip_tags($_POST['fullname']);
  10. $username = strip_tags($_POST['username']);
  11.  
  12. $password = strip_tags($_POST['password']);
  13. $repeatpassword = strip_tags($_POST['repeatpassword']);
  14. $date = date("Y-m-d");
  15. $email = strip_tags($_POST['email']);
  16. $dob_year = strip_tags($_POST['dob_year']);
  17. $dob_month = strip_tags($_POST['dob_month']);
  18. $dob_day = strip_tags($_POST['dob_day']);
  19. $gender = strip_tags($_POST['gender']);
  20.  
  21.  
  22.  
  23. //check for existance
  24. echo $submit,$fullname,$username,$password,$repeatpassword,$email,$dob_year,$dob_day,$dob_day,$gender;
  25. if($submit&&$fullname&&$username&&$password&&$repeatpassword&&$email&&$dob_year&&$dob_day&&$dob_day&&$gender)
  26. {
  27.  
  28. //$email=$_POST['email'];
  29.  
  30.  
  31.     if ($password==$repeatpassword)
  32.     {
  33.         //check char length of username and fullname
  34.         if (strlen($username)>25||strlen($fullname)>25)
  35.         {
  36.             echo "Length of username or fullname is too long!";
  37.         }
  38.         else
  39.         {
  40.             //check password length
  41.             if (strlen($password)>25||strlen($password)<6)
  42.             {
  43.                 echo "Password must be between 6 and 25 characters";
  44.             }
  45.             else
  46.             {
  47.             if ( ctype_digit($dob_year) && ctype_digit($dob_month) && ctype_digit($dob_day) )
  48.                {
  49.                   echo "Year, month and day of birth must be numeric values.";
  50.                   unset($dob_year);
  51.                   unset($dob_month);
  52.                   unset($dob_day);
  53.                }
  54.                else
  55.                {
  56.  
  57.                   if ( strlen($dob_year) > 4 || strlen($dob_year) > 2 || strlen($dob_year) > 2 )
  58.                      echo "Year of birth must be 4 characters long, month and day must be 2.";
  59.                      unset($dob_year);
  60.                      unset($dob_month);
  61.                      unset($dob_day);
  62.                   }
  63.                  
  64.                   //check dob limits for month and day
  65.                         if ($dob_month>12||$dob_day>31)
  66.                         {
  67.                            echo "Date of birth month or day is higher than expected!";
  68.                            unset($dob_year);
  69.                            unset($dob_month);
  70.                            unset($dob_day);
  71.                         }
  72.                  
  73.                   //check for existing user
  74.                            $query = mysql_query("SELECT * FROM users WHERE username='" . mysql_real_escape_string($username) . "' LIMIT 1");
  75.                            if (mysql_num_rows($query) > 0)
  76.                            {
  77.                               echo "That username is already taken.";
  78.                            }
  79.                  
  80.                            
  81.                 // enorypt password
  82.                 $password = md5($password);
  83.                 $repeatpassword = md5($repeatpassword = md5($repeatpassword));
  84.                
  85.                 //check email
  86.                 if (!ereg("[A-Z0-9._%-]+@[A-Z0-9.-]{2}([A-Z0-9.-])?\.[A-Z]{2,4}",$email)){                
  87.                 echo "Enter a valid E-mail Address";
  88.                 }
  89.  
  90.                 else{
  91.                
  92.                
  93.                  
  94.                  
  95.        
  96.                 //open database
  97.                 $connect = mysql_connect("localhost","root","");
  98.                 mysql_select_db("phplogin"); //select database
  99.        
  100.                 $queryreg = mysql_query("
  101.                 INSERT INTO users (`id`, `fullname`, `username`, `password`, `date`,`email`,`dob_year`,`dob_day`,`dob_day`,`gender`) VALUES (NULL, '$fullname', '$username', '$password', '$date','$email','$dob','$dob_year','$dob_day','$dob_day','$gender');
  102.                 ");
  103.                 if (!$queryreg)
  104.                 {
  105.                 die('Register Failed'.mysql_error());
  106.                
  107.                 }
  108.                
  109.                 echo "You have been registered! <a href='index.php'> Return to login page</a>";
  110.                 //close mail check
  111.                 }
  112.             }
  113.         }
  114.     }
  115.     else
  116.     {
  117.         echo "Your password do not match!";
  118.     }
  119. }
  120.     else
  121. {
  122.  echo "Please fill in <b>all<b> fields!";
  123. }
  124.  
  125.  
  126.  
  127. ?>
  128. <html>
  129. <p>
  130. <form action='register.php' method='POST'>
  131.   <table>
  132.      <tr>
  133.      <td>
  134.      Your full name:
  135.      </td>
  136.      <td>
  137.      <input type='text' name='fullname' value='<?php echo $fullname; ?>'
  138.      </td>
  139.      
  140.      <tr>
  141.      <td>
  142.      Choose a username:
  143.      </td>
  144.      <td>
  145.      <input type='text' name='username' value='<?php echo $username; ?>'
  146.      </td>   
  147.      <tr>
  148.      <td>
  149.      Choose a password:
  150.      </td>
  151.      <td>
  152.      <input type='password' name='password'>
  153.      </td>   
  154.      <tr>
  155.      <td>
  156.      Repeat your password:
  157.      </td>
  158.      <td>
  159.      <input type='password' name='repeatpassword'>
  160.      </td>
  161.      
  162.      </tr>   
  163.      
  164.      <tr>
  165.      <td>
  166.      Type Your Email:
  167.      </td>
  168.      <td>
  169.      <input type='text' name='email' value='<?php echo $email; ?>'
  170.      </td>
  171.      
  172.      <tr>
  173.             <td>
  174.             Date of birth:
  175.             </td>
  176.             <td>
  177.             <input type='text' name='dob_year' maxlength='4' size='3' value='<?php if ($dob_year) echo $dob_year; else echo "YYYY";?>'> /<input type='text' name='dob_month' maxlength='2' size='1' value='<?php if ($dob_month) echo $dob_month; else echo "MM";?>'> / <input type='text' name='dob_day' maxlength='2' size='1' value='<?php if ($dob_day) echo $dob_day; else echo "DD";?>'>
  178.             </td>
  179.       </tr>
  180.  
  181.   <tr>
  182.             <td>
  183.             Gender:
  184.             </td>
  185.             <td>
  186.             <select name='gender'>
  187.                <option value="F">Female</option>
  188.                <option value="M">Male</option>
  189.             </select>
  190.             </td>
  191.       </tr>
  192.      
  193.      
  194.   </table>
  195.   <p>
  196.   <input type='submit' name='submit' value='Register'>
  197.  
  198. </form>
  199.  
  200. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement