Advertisement
Guest User

Untitled

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