Advertisement
Guest User

kinda works :o

a guest
Feb 4th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. <?php
  2. class Connect
  3. {
  4. public function __construct()
  5. {
  6. try
  7. {
  8. $this->db = new PDO("mysql:host=localhost;dbname=aaron_test",'aaron_test','d6G4X5S54');
  9. }
  10. catch(PDOException $e)
  11. {
  12. echo $e->getMessage();
  13. }
  14. }
  15.  
  16. public function login($name, $pass)
  17. {
  18. if(!empty($name) && !empty($pass))
  19. {
  20. $st = $this->db->prepare("SELECT * FROM users WHERE username= ? and password= ?");
  21. $st->bindParam(1, $name);
  22. $st->bindParam(2, $pass);
  23. $st->execute();
  24.  
  25. if($st->rowCount() == 1)
  26. {
  27. echo "Access Granted.";
  28. }
  29. else
  30. {
  31. echo "incorrect username or password.";
  32. }
  33. }
  34. else
  35. {
  36. echo "Please supply a username and password.";
  37. }
  38. }
  39.  
  40. }
  41.  
  42. if(isset($_POST['submit']))
  43. {
  44. $name = $_POST['user'];
  45. $pass = $_POST['pass'];
  46.  
  47. $object = new Connect();
  48. $object->login($name, $pass);
  49. }
  50. ?>
  51.  
  52.  
  53.  
  54. <form action="" method="POST">
  55. Username: <input type="text" name="user">
  56. Password: <input type="text" name="password">
  57. <input type="submit" name="submit" value="Login">
  58. </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement