Advertisement
Guest User

Untitled

a guest
Nov 5th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. if (isset($_POST['login_user'])) {
  2. $username = mysqli_real_escape_string($db, $_POST['username']);
  3. $password = mysqli_real_escape_string($db, $_POST['password']);
  4.  
  5. if (empty($username)) {
  6. array_push($errors, "Username is required");
  7. }
  8. if (empty($password)) {
  9. array_push($errors, "Password is required");
  10. }
  11.  
  12. if (count($errors) == 0) {
  13. $password = md5($password);
  14. $query = "SELECT * FROM users WHERE username='$username' AND password='$password'";
  15. $results = mysqli_query($db, $query);
  16.  
  17. if (mysqli_num_rows($results) == 1) {
  18. $_SESSION['username'] = $username;
  19. $_SESSION['success'] = "You are now logged in";
  20. header('location: index.php');
  21. }else {
  22. array_push($errors, "Wrong username/password combination");
  23. }
  24. }
  25. }
  26.  
  27. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement