Advertisement
Guest User

Untitled

a guest
Aug 30th, 2016
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.92 KB | None | 0 0
  1. $target_file = $target_path . basename ($_FILES['image']['name']);
  2.  
  3. <?php
  4.  
  5. //start the session before anything is echoed to the browser
  6. if (session_status()===PHP_SESSION_NONE) {
  7. session_start();
  8. }
  9.  
  10. ?>
  11. <!DOCTYPE html>
  12. <html>
  13. <head>
  14. <title>
  15. Login form
  16. </title>
  17. </head>
  18. <body>
  19. <h3>Registration Form</h3>
  20. <form action ="" method="POST">
  21. <table align="center" cellpadding="10">
  22. <tr>
  23. <td>Name</td>
  24. <td><input type="text" maxlength='100' name="empname" id="empname" required></td>
  25. </tr>
  26. <tr>
  27. <td>Email Id</td>
  28. <td><input type="text" maxlength='100' name="emailid" id="emailid" required>
  29. </td>
  30. </tr>
  31. <tr>
  32. <td>User Id</td>
  33. <td><input type="text" maxlength='100' name="userid" id="userid" required ></td>
  34. </tr>
  35. <tr>
  36. <td>Password</td>
  37. <td><input type="password" maxlength='100' name="pwd" id="pwd" required ></td>
  38. </tr>
  39. <tr>
  40. <td>Date of Birth</td>
  41. <td>
  42. <select name='year'>
  43. <option value='1996'>1996</option>
  44. <option value='1997'>1997</option>
  45. <option value='1998'>1998</option>
  46. <option value='1999'>1999</option>
  47. <option value='2000'>2000</option>
  48. <option value='2001'>2001</option>
  49. <option value='2002'>2002</option>
  50. <option value='2003'>2003</option>
  51. <option value='2004'>2004</option>
  52. <option value='2005'>2005</option>
  53. <option value='2006'>2006</option>
  54. <option value='2007'>2007</option>
  55. <option value='2008'>2008</option>
  56. <option value='2009'>2009</option>
  57. <option value='2010'>2010</option>
  58. <option value='2011'>2011</option>
  59. <option value='2012'>2012</option>
  60. <option value='2013'>2013</option>
  61. <option value='2014'>2014</option>
  62. <option value='2015'>2015</option>
  63. <option value='2016'>2016</option>
  64. </select>
  65. <select name='month'>
  66. <option value='01'>January</option>
  67. <option value='02'>February</option>
  68. <option value='03'>March</option>
  69. <option value='04'>April</option>
  70. <option value='05'>May</option>
  71. <option value='06'>June</option>
  72. <option value='07'>July</option>
  73. <option value='08'>August</option>
  74. <option value='09'>September</option>
  75. <option value='10'>October</option>
  76. <option value='11'>November</option>
  77. <option value='12'>December</option>
  78. </select>
  79. <select name='day'>
  80. <option value='01'>1</option>
  81. <option value='02'>2</option>
  82. <option value='03'>3</option>
  83. <option value='04'>4</option>
  84. <option value='05'>5</option>
  85. <option value='06'>6</option>
  86. <option value='07'>7</option>
  87. <option value='08'>8</option>
  88. <option value='09'>9</option>
  89. <option value='10'>10</option>
  90. <option value='11'>11</option>
  91. <option value='12'>12</option>
  92. <option value='13'>13</option>
  93. <option value='14'>14</option>
  94. <option value='15'>15</option>
  95. <option value='16'>16</option>
  96. <option value='17'>17</option>
  97. <option value='18'>18</option>
  98. <option value='19'>19</option>
  99. <option value='20'>20</option>
  100. <option value='21'>21</option>
  101. <option value='22'>22</option>
  102. <option value='23'>23</option>
  103. <option value='24'>24</option>
  104. <option value='25'>25</option>
  105. <option value='26'>26</option>
  106. <option value='27'>27</option>
  107. <option value='28'>28</option>
  108. <option value='29'>29</option>
  109. <option value='30'>30</option>
  110. <option value='31'>31</option>
  111. </select></td>
  112. </tr>
  113. <tr>
  114. <td>Designation</td>
  115. <td><input type="text" maxlength='100' name="designation" id="designation" required></td>
  116. </tr>
  117. <tr>
  118. <td>Department</td>
  119. <td><input type="text" maxlength='100' name="department" id="department" required></td>
  120. </tr>
  121. <tr>
  122. <td>Image</td>
  123. <td><input type="file" maxlength='100' name="image" required></td>
  124. </tr>
  125. <tr>
  126. <td>
  127. <input type="submit" name="login" value="Register Yourself">
  128. </td>
  129. </tr>
  130. </table>
  131. </form>
  132. </body>
  133. </html>
  134. <?php
  135. //create a connection
  136. $conn = mysqli_connect('localhost', 'root', '', 'attendance');
  137.  
  138. //on the click of submit button
  139. if (isset($_POST['login'])) {
  140.  
  141. //capture the $_POST values
  142. $name = $_POST['empname'];
  143. $name = trim($name);
  144. $email = $_POST['emailid'];
  145. $email = trim($email);
  146. $userid = $_POST['userid'];
  147. $userid = trim($userid);
  148. $pwd = $_POST['pwd'];
  149. $pwd = trim($pwd);
  150. $desg = $_POST['designation'];
  151. $desg = trim($desg);
  152. $dept = $_POST['department'];
  153. $dept = trim($dept);
  154. $day = $_POST['day'];
  155. $month = $_POST['month'];
  156. $year = $_POST['year'];
  157. $date = $year.$month.$day;
  158.  
  159. //display a message if there is a blank entry for email
  160. if ($email=="") {
  161. echo "Please enter a valid email id";
  162. }
  163.  
  164. //display a message if there is a blank entry for userid
  165. if ($userid=="") {
  166. echo "Please enter a valid User Id";
  167. }
  168.  
  169. //check if the email id exists
  170. $sql_check_email = "select * from employee where emp_email='$email';";
  171.  
  172. mysqli_query($conn, $sql_check_email);
  173.  
  174. $aff_email = mysqli_affected_rows($conn);
  175.  
  176. // if email id exists ..display message
  177. if ($aff_email==1) {
  178.  
  179. $msgemail = "The email id exists";
  180. echo $msgemail;
  181.  
  182. //display error message if there is an error
  183. } else if ($aff_email>1) {
  184.  
  185. $msgemail = "There are multiple employees with the same email";
  186. echo $msgemail;
  187.  
  188. //display message if there is an error firing the query
  189. } else if ($aff_email<0) {
  190.  
  191. echo "There is an error ..Try again";
  192.  
  193. }
  194.  
  195. //check if the user id exists
  196. $sql_check_userid = "select * from employee_login where emp_uid='$userid';";
  197.  
  198. mysqli_query($conn, $sql_check_userid);
  199.  
  200. $aff_userid = mysqli_affected_rows($conn);
  201.  
  202. if ($aff_userid==1) {
  203.  
  204. $umsg = "User id already exist";
  205.  
  206. echo $umsg;
  207.  
  208. //display error message if there is an error when the query is fired
  209. } else if ($aff_userid<0) {
  210.  
  211. echo "There is an error ..Try again";
  212.  
  213. }
  214.  
  215. //if neither the user id nor the email id exist, upload image and do the insert
  216. if ($aff_userid==0 && $aff_email==0) {
  217.  
  218. $target_path = "images/";
  219. $target_file = $target_path . basename ($_FILES['image']['name']);
  220.  
  221. //if the image is moved to the images folder , do the insert
  222. if (move_uploaded_file($_FILES['image']['tmp_name'], $target_file)) {
  223.  
  224. $image = basename($_FILES['image']['name']);
  225.  
  226. $sql_ins = "INSERT INTO temporary_employee(emp_uid,emp_pwd,
  227. emp_name,emp_email,emp_dob,emp_designation,
  228. emp_department,emp_image)
  229. VALUES('$userid','$pwd','$name','$email','$date',
  230. '$desg','$dept','$image')";
  231.  
  232. mysqli_query($conn, $sql_ins);
  233.  
  234. $aff_insert = mysqli_affected_rows($conn);
  235.  
  236. //display success message if insert is successfull
  237. if ($aff_insert==1) {
  238.  
  239. echo "You have successfully registered ...awaiting approval by admin";
  240.  
  241. //display message if there were no insert
  242. } else if ($aff_insert==0) {
  243.  
  244. echo "The registration has failed ..Try again";
  245.  
  246. //diplay error message if there was an error while firing the insert query
  247. } else if ($aff_insert<0) {
  248.  
  249. echo "There was an error ..Try again";
  250. }
  251.  
  252. }
  253.  
  254.  
  255. }
  256.  
  257. }
  258.  
  259. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement