Advertisement
Guest User

Untitled

a guest
Oct 16th, 2016
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. <?php
  2. require('db.php');
  3. session_start();
  4. // If form submitted, insert values into the database.
  5. if (isset($_POST['username'])){
  6.  
  7. $username = stripslashes($_REQUEST['username']); // removes backslashes
  8. $username = mysqli_real_escape_string($con,$username); //escapes special characters in a string
  9. $password = stripslashes($_REQUEST['password']);
  10. $password = mysqli_real_escape_string($con,$password);
  11.  
  12. //Checking is user existing in the database or not
  13. $query = "SELECT * FROM `users` WHERE username='$username' and password='".md5($password)."'";
  14. $result = mysqli_query($con,$query) or die(mysql_error());
  15. $rows = mysqli_num_rows($result);
  16.  
  17. if($rows==1)
  18. {
  19. if($rows ['level'] == "student")
  20. {
  21. header("localtion: student.php");
  22. }
  23. elseif($rows ['level'] == "manager")
  24. {
  25. header("location: manager.php");
  26. }
  27. }
  28. else
  29. {
  30. echo "wrong Username or Password";
  31. }
  32. ?>
  33. <!DOCTYPE html>
  34. <html>
  35. <head>
  36. <meta charset="utf-8">
  37. <title>Login</title>
  38. <link rel="stylesheet" href="css2/style.css" />
  39. </head>
  40. <body>
  41.  
  42. <div class="form">
  43. <h1>Log In</h1>
  44. <form action="" method="post" name="login">
  45. <input type="text" name="username" placeholder="Username" required />
  46. <input type="password" name="password" placeholder="Password" required />
  47. <input name="submit" type="submit" value="Login" />
  48. </form>
  49. <p>Not registered yet? <a href='registration.php'>Register Here</a></p>
  50.  
  51. </div>
  52. <?php } ?>
  53.  
  54.  
  55. </body>
  56. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement