Advertisement
Guest User

Untitled

a guest
Aug 19th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.03 KB | None | 0 0
  1. <?php
  2.  
  3. include ("Design/header.php");
  4. require ("connect.php");
  5.  
  6. //register code
  7.  
  8. if ($_POST['submit'])
  9. {
  10.     //grab submitted data
  11.     $firstname=         $_POST ['firstname'];
  12.     $lastname=          $_POST ['lastname'];
  13.     $username=          $_POST ['username'];
  14.     $password=          $_POST ['password'];
  15.     $password_repeat=   $_POST ['password_repeat'];
  16.    
  17.     $dob_year=          $_POST ['dob_year'];
  18.     $dob_month=         $_POST ['dob_month'];
  19.     $dob_day=           $_POST ['dob_day'];
  20.    
  21.     $gender=            $_POST ['gender'];
  22.    
  23.     if (
  24.     $firstname&&
  25.     $lastname&&
  26.     $username&&
  27.     $password&&
  28.     $password_repeat&&
  29.     $dob_year&&
  30.     $dob_month&&
  31.     $dob_day&&
  32.     $gender
  33.     )
  34.     {
  35.        
  36.         //validate
  37.         if (strlen($firstname)>25 || strlen($lastname)>25 || strlen($username)>25)
  38.             echo "Firstname, Lastname and Username must be no more that 25 characters.";
  39.         else
  40.         {
  41.            
  42.             //check password
  43.             if (strlen($password)>25 || strlen($password)<6)
  44.                 echo "Password must be between 6 and 25 characters.";
  45.             else
  46.             {
  47.                 //check dob
  48.                 if (is_numeric($dob_year)&&is_numeric($dob_month)&&is_numeric($dob_day))
  49.                 {
  50.                    
  51.                     if(strlen($dob_year)>4 || strlen($dob_month)>2 || strlen($dob_day)>2 )
  52.                     echo "Date of Birth must be in the following format, 1919/01/31.";
  53.                     else
  54.                     {
  55.                        
  56.                         if ($gender=="Male"||$gender=="Female")
  57.                         {
  58.                             //compare passwords
  59.                             if ($password==$password_repeat)
  60.                             {
  61.                                 //check Date of Birth limits for month and day
  62.                                 if ($dob_month>12||$dob_month>31)
  63.                                 echo "Date of Birth month and/or day is bigger then expected.";
  64.                                 else
  65.                                 {
  66.                                 //success register the user
  67.                                 $dob_db = "$dob_year-$dob_month-$dob_day";
  68.                                 $password_db = md5(password);
  69.                                
  70.                                 switch ($gender)
  71.                                 {
  72.                                     case "Male";
  73.                                     $gender_db = "M";
  74.                                     break;
  75.                                     case "Female";
  76.                                     $gender_db = "F";
  77.                                     break; 
  78.                                 }
  79.                            
  80.                                
  81. $register = mysql_query ("INSERT INTO users VALUES ('','$firstname','$lastname;,$username','$password_db','$dob_db','$gender_db')");
  82.                             echo "Success!";   
  83.                                 }
  84.                             }
  85.                             else
  86.                                 echo "The two passwords you have entered do not match, please try again.";
  87.                            
  88.                         }
  89.                         else
  90.                             echo "Gender must be Male of Female.";
  91.                        
  92.                     }
  93.                    
  94.                 }
  95.                 else
  96.                     echo "Date of Birth must be in number form, For example 1919/01/01.";
  97.             }
  98.            
  99.         }
  100.    
  101.     }
  102.     else
  103.         echo "Missing field! Please fill in all fields.";
  104.    
  105. }
  106. else
  107.     echo "Please enter your details and Register.";
  108.  
  109. ?>
  110.  
  111. <form action='register.php' method='POST'>
  112.  
  113. <p>
  114. <table width='60%'>
  115.         <tr>
  116.             <td width='40%' align='right'>
  117.             <font size='2' font face='arial'>First name -
  118.             </td>
  119.             <td>
  120.             <input type='text' value='<?php echo $firstname; ?>' name='firstname' maxlength='25'>
  121.             </td>
  122.         </tr>
  123.         <tr>
  124.             <td width='40%' align='right'>
  125.             <font size='2' font face='arial'>Last name -
  126.             </td>
  127.             <td>
  128.             <input type='text' value='<?php echo $lastname; ?>' name='lastname' maxlength='25'>
  129.             </td>
  130.         </tr>
  131.         <tr>
  132.             <td width='40%' align='right'>
  133.             <font size='2' font face='arial'>Username -
  134.             </td>
  135.             <td>
  136.             <input type='text' value='<?php echo $username; ?>' name='username' maxlength='25'>
  137.             </td>
  138.         </tr>
  139.         <tr>
  140.             <td width='40%' align='right'>
  141.             <font size='2' font face='arial'>Password -
  142.             </td>
  143.             <td>
  144.             <input type='password' name='password' maxlength='25'>
  145.             </td>
  146.         </tr>
  147.         <tr>
  148.             <td width='40%' align='right'>
  149.             <font size='2' font face='arial'>Repeat password -
  150.             </td>
  151.             <td>
  152.             <input type='password' name='password_repeat' maxlength='25'>
  153.             </td>
  154.         </tr>
  155.          <tr>
  156.             <td width='40%' align='right'>
  157.             <font size='2' font face='arial'>Date of Birth -
  158.             </td>
  159.             <td>
  160.             <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";?>'>
  161.             <tr>
  162.             <td width='40%' align='right'>
  163.             <font size='2' font face='arial'>Gender -
  164.             </td>
  165.             <td>
  166.             <select name='gender'>
  167.                 <option>Male</option>
  168.                 <option>Female</option>
  169.             </select>
  170.             </td>
  171.         </tr>
  172.             </td>
  173.         </tr>
  174.         <tr>
  175.             <td width='40%' align='right'>
  176.             <input type='submit' name='submit' value='Register'>
  177.             </td>
  178.             <td>
  179.             </td>
  180.         </tr>
  181. </table>
  182.  
  183. </form>
  184.  
  185. <?php
  186.  
  187. include ("Design/footer.php");     
  188.  
  189. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement