Advertisement
Guest User

Untitled

a guest
May 15th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. <?php
  2.  
  3. $output='';
  4.  
  5. if (isset($_POST['submit'])){
  6.  
  7. $username = $_POST['username'];
  8. $password = $_POST['password'];
  9.  
  10. if(empty($_POST['username']) || empty($_POST['password'])){
  11. $output = "Username or Password is Invalid";
  12. }
  13. else
  14. {
  15.  
  16. //Connect with server
  17. $mysqli = NEW Mysqli ('localhost', 'root', '', 'accounts');
  18.  
  19. $username = $mysqli->real_escape_string ($_POST['username']);
  20. $password = $mysqli->real_escape_string ($_POST['password']);
  21. //finds user match.
  22. $query = mysqli_query($mysqli, "SELECT * FROM users WHERE password= md5 ('$password') AND username='$username'");
  23.  
  24. $rows = mysqli_num_rows($query);
  25.  
  26. if($rows == 1){
  27. session_start();
  28. $_SESSION["user"] = $username;
  29. header('Location: profile.php'); //directing to other page
  30. }
  31. else{
  32.  
  33. $output = "Username and Password did not match our records";
  34. }
  35.  
  36. mysqli_close($mysqli); // Close connection
  37. }
  38.  
  39. }
  40.  
  41. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement