Advertisement
Guest User

session _problem

a guest
Jun 24th, 2018
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <?php
  3. session_start();
  4. include ('connection.php');
  5.  
  6.  
  7.  
  8. if (isset($_POST['user']) and isset($_POST['password'])){
  9.  
  10. $username = $_POST['user'];
  11. $password = $_POST['password'];
  12.  
  13. $query = "SELECT * FROM users WHERE stud_matricno ='$username' and stud_password='$password'";
  14. $result = mysqli_query($conn, $query) or die(mysqli_error($conn));
  15. $get_log = mysqli_fetch_assoc($result);
  16. $count = mysqli_num_rows($result);
  17.  
  18. if ($count == 1){
  19. $_SESSION['user'] = $username;
  20.  
  21. while($row = mysqli_fetch_assoc($result)) {
  22. $status = $row["status"];
  23. }
  24. if($status == 'student'){
  25. $qr_log1 = "SELECT * FROM users WHERE stud_matricno ='$username'";
  26. $result1 = mysqli_query($conn,$qr_log1);
  27. $get_log1 = mysqli_fetch_assoc($result1);
  28. $get_password = $get_log1['stud_password'];
  29. $get_username = $get_log1['stud_matricno'];
  30.  
  31. if($password !== $get_password)
  32. {
  33. print "<script language=\"javascript\" type=\"text/javascript\">
  34. <!--
  35. window.setTimeout('window.location=\"index.php\"; ',0);
  36. //-->
  37. </script> ";
  38. echo "<script type='text/javascript'>alert('Wrong password. Please try again!');</script>";
  39. echo mysqli_error($con);
  40. }
  41. else
  42. {
  43. $_SESSION['stud_matricno']=$get_username;
  44. print "<script language=\"javascript\" type=\"text/javascript\">
  45. <!--
  46. window.setTimeout('window.location=\"student.php\"; ',0);
  47. //-->
  48. </script> ";
  49. echo "<script>alert('Congratulation, you have sucessful login into the site!');</script>";
  50.  
  51. }
  52. }elseif ($status == 'staff'){
  53. header("location: /completeise/staff/content/index.php");
  54.  
  55. }else if ($status == 'admin'){
  56. header("location: /completeise/admin/content/index.php");
  57.  
  58. }
  59.  
  60.  
  61. } else{
  62. print "<script language=\"javascript\" type=\"text/javascript\">
  63. <!--
  64. window.setTimeout('window.location=\"error.php\"; ',0);
  65. //-->
  66. </script> ";
  67. echo "<script>alert('Username not registered yet!');</script>";
  68. }
  69. }
  70. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement