Advertisement
Guest User

Echo employeeID

a guest
May 30th, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. <?php
  2. // creating error message variable
  3. $errorMessage = '';
  4. // ensuring page is not cached
  5. require_once("nocache.php");
  6. // check that the form has been submitted
  7. if(isset($_POST['submit'])) {
  8. // check that employee and password were entered
  9. if(empty($_POST['employeeid']) || empty($_POST['pword'])) {
  10. // display error message if strings are empty
  11. $errorMessage = "*Both employee ID and password are required to login.";
  12. } else {
  13. // connect to the database
  14. require_once('conn.php');
  15. // parse username and password for special characters
  16. $employeeid= $dbConn->escape_string($_POST['employeeid']);
  17. $password = $dbConn->escape_string($_POST['pword']);
  18. // hash the password so it can be compared with the db value
  19. $hashedPassword = hash('sha256', $password);
  20. // query the db
  21. $sql = "SELECT * FROM staff WHERE employee_id = '$employeeid' AND password= '$hashedPassword'";
  22. $rs = $dbConn->query($sql);
  23. // check number of rows in record set
  24. if($rs->num_rows) {
  25. // start a new session for the user
  26. session_start();
  27. // store the employee details in session variables
  28. $employeeid = $rs->fetch_assoc();
  29. $_SESSION['who'] = $employeeid['employeeid'];
  30. $_SESSION['who'] = $employeeid['category'];
  31. // redirect the user to the secure page
  32. header('Location: findpatient.php');
  33. } else {
  34. // display error message if wrong username and password
  35. $errorMessage = "*The Employee ID or Password entered is invalid.";
  36. }
  37. }
  38. }
  39. ?>
  40.  
  41. <!DOCTYPE html>
  42. <html>
  43. <head>
  44. <meta charset="utf-8">
  45. <title>Glebe Family Medical Practice Patient Records Application</title>
  46. <link rel="stylesheet" href="style.css">
  47. </head>
  48.  
  49. <body>
  50.  
  51. <h1>Glebe Family Medical Practice Patient Record Application</h1>
  52.  
  53. <form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
  54. <div class="input-box">
  55. <label for="employeeid">Employee ID:</label>
  56. <input type="text" name="employeeid" maxlength="50" id="employeeid">
  57. </div>
  58. <div class="input-box">
  59. <label for="pword">Password:</label>
  60. <input type="password" name="pword" maxlength="20" id="pword">
  61. </div>
  62. <p class="error-php"><?php echo $errorMessage;?></p>
  63. <div class="input-box">
  64. <input type="submit" value="Login" name="submit">
  65. </div>
  66. </form>
  67.  
  68. </body>
  69.  
  70.  
  71. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement