Advertisement
Baldwin1

login.pho1

Dec 30th, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. <?php
  2. error_reporting(-1);
  3. ini_set('display_errors', 'On');
  4. include("config.php");
  5. session_start();
  6. $link = mysqli_connect('mysql3.gear.host','baldwin','Baldwin1#','userinfo');
  7.  
  8. if($_SERVER["REQUEST_METHOD"] == "POST") {
  9. // username and password sent from form
  10. $username = mysqli_real_escape_string($link, $_POST['username']);
  11. $password = mysqli_real_escape_string($link, $_POST['password']);
  12.  
  13. $result = mysqli_query($link, "SELECT * FROM users WHERE username LIKE '$username' AND password LIKE '$password'");
  14.  
  15. if($result === FALSE) {
  16. die(mysql_error()); // TODO: better error handling
  17. }
  18.  
  19. while($row = mysqli_fetch_array($result))
  20. {
  21.  
  22. echo $row['username'];
  23. }
  24.  
  25. echo var_dump($result);
  26. $active = $row['active'];
  27.  
  28. $count = mysqli_num_rows($result);
  29.  
  30. // If result matched $username and $password, table row must be 1 row
  31.  
  32. if($count == 1) {
  33.  
  34. $_SESSION['login_user'] = $username;
  35.  
  36. // check the user_type
  37. if($row["user_type"] == "teacher")
  38. {
  39. header("Location: teacher.php");
  40. }
  41. elseif($row["user_type"] == "parent")
  42. {
  43. header("Location: parent.php");
  44. }
  45. elseif($row ["user_type"] == "student")
  46. {
  47. header("Location: student.php");
  48. }
  49. elseif($row ["user_type" == "HOD")
  50. {
  51. header("Location: HOD.php");
  52. }
  53. else {
  54. echo "no account type!";
  55.  
  56. }else {
  57. $error = "Your Login Name or Password is invalid";
  58. }
  59. }
  60. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement