Advertisement
Guest User

Untitled

a guest
Dec 12th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.56 KB | None | 0 0
  1. <?php
  2.  
  3. $host = "localhost";
  4. $dbname = "tennis";
  5. $username = "root";
  6. $password = "";
  7.  
  8. //Start the Session
  9. session_start();
  10.  
  11. $pdo = new PDO("mysql:host=$host;dbname=$dbname;charset=utf8", $username, $password);
  12.  
  13.  
  14.  
  15. //3. If the form is submitted or not.
  16. //3.1 If the form is submitted
  17. if (isset($_POST['email']) and isset($_POST['password'])){
  18.  
  19. //3.1.1 Assigning posted values to variables.
  20. $email = $_POST['email'];
  21. $password = $_POST['password'];
  22.  
  23. var_dump($_POST); die;
  24.  
  25.  
  26. //3.1.2 Checking the values are existing in the database or not
  27. $query = "SELECT * FROM `users` WHERE email='$email' and password='$password'";
  28.  
  29. $result = $pdo->query("SELECT * FROM users WHERE email='$email' and password='$password'")->fetch(PDO::FETCH_ASSOC);
  30.  
  31. var_dump($result); die;
  32.  
  33. $result = mysqli_query($connection, $query) or die(mysqli_error($connection));
  34. $count = mysqli_num_rows($result);
  35.  
  36. //3.1.2 If the posted values are equal to the database values, then session will be created for the user.
  37. if ($count == 1){
  38. $_SESSION['username'] = $username;
  39. }else{
  40.  
  41. //3.1.3 If the login credentials doesn't match, he will be shown with an error message.
  42. $fmsg = "Invalid Login Credentials.";
  43. }
  44. }
  45.  
  46. //3.1.4 if the user is logged in Greets the user with message
  47. if (isset($_SESSION['username'])){
  48. $username = $_SESSION['username'];
  49. echo "Hai " . $username . "
  50. ";
  51. echo "This is the Members Area
  52. ";
  53. echo "<a href='logout.php'>Logout</a>";
  54.  
  55. }else{
  56. //3.2 When the user visits the page first time, simple login form will be displayed.
  57.  
  58. }
  59. require('login.phtml');
  60. die;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement