Advertisement
Guest User

Untitled

a guest
Apr 9th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. <?php
  2. session_start();
  3. $host = "localhost";
  4. $username = "toxic";
  5. $password = "sysop2018";
  6. $database = "oversurgery";
  7. $message = "";
  8. try
  9. {
  10. $connect = new PDO("mysql:host=$host; dbname=$database", $username, $password);
  11. $connect->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  12. if(isset($_POST["loginbtn"]))
  13. {
  14. if(empty($_POST["username"]) || empty($_POST["password"]))
  15. {
  16. $message = '<label>All fields are required</label>';
  17. }
  18. else
  19. {
  20. $query = 'SELECT * FROM register WHERE username = :username AND password = :password';
  21. $statement = $connect->prepare($query);
  22. $statement->execute(
  23. array(
  24. ':username' => $_POST["username"],
  25. ':password' => $_POST["password"]
  26. ));
  27. $count = $statement->rowCount();
  28. if($count > 0)
  29. {
  30. //fetch row
  31. $row = $statement->fetch(PDO::FETCH_OBJ);
  32. $_SESSION["username"] = $_POST["username"];
  33. $_SESSION["userid"] = $row->userid;
  34. header("location:dashboard.php");
  35. }
  36. else
  37. {
  38. $message = '<div id="alert1" class="alert alert-danger alert-dismissible" role="alert">
  39. <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>Invalid Username or Password.<div>';
  40. }
  41. }
  42. }
  43. }
  44. catch(PDOException $error)
  45. {
  46. $message = $error->getMessage();
  47. }
  48. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement