Guest User

Untitled

a guest
Jun 8th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.28 KB | None | 0 0
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
  5. <script src="script.js"></script>
  6. <style>
  7. .error {
  8. color:red;
  9. }
  10.  
  11. .button {
  12. background-color: #4CAF50;
  13. border: none;
  14. color: white;
  15. padding: 10px 25px;
  16. text-align: center;
  17. text-decoration: none;
  18. display: inline-block;
  19. font-size: 16px;
  20. margin: 4px 2px;
  21. cursor: pointer;
  22. }
  23. .div1 {
  24.  
  25. margin-top: -19px;
  26. margin-bottom: -25px;
  27. margin-left: -19px;
  28. }
  29.  
  30. .copy {
  31. border-radius: 4px;
  32. padding: 6px 20px;
  33. border-style: ridge;
  34. }
  35.  
  36. .copy1{
  37. border-radius: 4px;
  38. padding: 6px 28px;
  39. border-style: ridge;
  40. }
  41.  
  42. .copy2{
  43. border-radius: 4px;
  44. padding: 4px 2px;
  45.  
  46. }
  47. </style>
  48. </head>
  49. <body style="background-color:#1affff">
  50.  
  51. <div style="padding-left: 250px; padding-top:50px" class="div1">
  52.  
  53. <h2 style="color:#009999">Registration Form :</h2>
  54.  
  55. <p><span class="error">All fields are required </span></p>
  56.  
  57. <form action="" method="post" enctype="multipart/form-data">
  58.  
  59. <span style="color:#0099ff">Name: </span>
  60. <input type="text" name="name" class= "name copy" style="margin-left: 52px" value ="">
  61. <span class="namee error"> </span>
  62. <br><br>
  63.  
  64. <span style="color:#0099ff"> E-mail: </span>
  65. <input type="text" name="email" class= "email copy" style="margin-left: 48px" value ="">
  66. <span class="emaile error"></span>
  67. <br><br>
  68.  
  69. <span style="color:#0099ff"> Username: </span>
  70. <input type="text" name="username" class= "username copy" style="margin-left:26px" value ="">
  71. <span class="usernamee error"></span>
  72. <br><br>
  73.  
  74. <span style="color:#0099ff"> Password: </span>
  75. <input type="password" name="password" class= "password copy" style="margin-left:30px">
  76. <span class="passworde error"> </span>
  77. <br><br>
  78.  
  79. <span style="color:#0099ff"> Age : </span>
  80. <input type="number" name="age" class= "age copy" style="margin-left:62px" value ="">
  81. <span class="agee error"> </span>
  82. <br><br>
  83.  
  84. <span style="color:#0099ff"> Date Of Birth : </span>
  85. <input type="date" name="date_of_birth" class= "date_of_birth copy" style="margin-left:14px" value ="">
  86. <span class="date_of_birthe error"> </span>
  87. <br><br>
  88.  
  89. <span style="color:#0099ff"> Department : </span>
  90.  
  91. <select name="department" class= "department copy" style="margin-left:14px" value ="">
  92. <option disabled selected value> -- select an option -- </option>
  93. <option value="EE">Electrical & Electronics</option>
  94. <option value="EC">Electronics & Communication</option>
  95. <option value="ME">Mechanical</option>
  96. <option value="CS">Computer Science</option>
  97. <option value="CV">Civil</option>
  98. <option value="IS">Information Science</option>
  99. </select>
  100. <span class="departmente error"> </span>
  101. <br><br>
  102.  
  103. <input type="button" class="submit" name="submit" value="Register">
  104.  
  105. </form>
  106.  
  107. </div>
  108.  
  109. </body>
  110.  
  111. <script>
  112. $(document).ready(function(){
  113. $(".submit").click(function(){
  114.  
  115. var name = $(".name").val();
  116. var email = $(".email").val();
  117. var username = $(".username").val();
  118. var password = $(".password").val();
  119. var age = $(".age").val();
  120. var date_of_birth = $(".date_of_birth").val();
  121. var department = $(".department").val();
  122.  
  123. if(name==''){$('.namee').text('Enter name'); return false}
  124. if(email==''){$('.emaile').text('Enter email'); return false}
  125. if(username==''){$('.usernamee').text('Enter username'); return false}
  126. if(password==''){$('.passworde').text('Enter password'); return false}
  127. if(age==''){$('.agee').text('Enter age'); return false}
  128. if(date_of_birth==''){$('.date_of_birthe').text('Enter date_of_birth'); return false}
  129. if(department==''){$('.departmente').text('Enter department'); return false}
  130.  
  131.  
  132. // Returns successful data submission message when the entered information is stored in database.
  133. var dataString = 'name='+ name + '&email='+ email + '&username='+ username + '&password='+ password + '&age='+ age + '&date_of_birth='+ date_of_birth + '&department='+ department;
  134.  
  135.  
  136. // AJAX Code To Submit Form.
  137. $.ajax({
  138. type: "POST",
  139. url: "gethint.php",
  140. data: dataString,
  141. cache: false,
  142. success: function(result){
  143. alert(result);
  144. }
  145. });
  146.  
  147. });
  148. });
  149. </script>
  150.  
  151. </html>
  152.  
  153. <?php
  154.  
  155.  
  156.  
  157. $mysqli = mysqli_connect("localhost","root","","ajax");
  158.  
  159. $username =$_POST["username"];
  160. $password=$_POST["password"];
  161. $hashed_password = password_hash($password, PASSWORD_DEFAULT);
  162. $email=$_POST["email"];
  163. $name=$_POST["name"];
  164. $age=$_POST["age"];
  165. $date_of_birth=$_POST["date_of_birth"];
  166. $department=$_POST["department"];
  167.  
  168. $check="SELECT * FROM users WHERE username = '$_POST[username]'";
  169. $rs = mysqli_query($mysqli,$check);
  170. $da = mysqli_fetch_array($rs, MYSQLI_NUM);
  171. if($da[0] > 0) {
  172. echo "Username Already in Exists<br/>";
  173. }
  174. else
  175. {
  176. $sql = "INSERT INTO users(`userid`,`username`, `password`, `email` , `name` , `age` , `date_of_birth` , `department`)
  177. VALUES ('','".$username."', '".$hashed_password."', '".$email."' , '".$name."' , '".$age."' , '".$date_of_birth."' , '".$department."')";
  178.  
  179. if (mysqli_query($mysqli, $sql)) {
  180. echo "Registered successfully";
  181. } else {
  182. echo "Error: " . $sql . "<br>" . mysqli_error($mysqli);
  183. }
  184. mysqli_close($mysqli);
  185. }
  186.  
  187.  
  188. ?>
Add Comment
Please, Sign In to add comment