Advertisement
Guest User

PHP/MySQL Login Form

a guest
Aug 10th, 2016
536
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.88 KB | None | 0 0
  1. <?php
  2.  
  3. $host = "localhost";
  4. $user = "root";
  5. $pass = "";
  6. $db = "fast";
  7.  
  8. mysql_connect($host, $user, $pass);
  9. mysql_select_db($db);
  10.  
  11.     if (isset ($_POST['username'])) {
  12.         $username = $_POST['username'];
  13.         $password = $_POST['password'];
  14.     $sql = "SELECT * FROM users WHERE username='".$username."' AND password='".$password."' LIMIT 1";
  15.     $res = mysql_query($sql);
  16.     if (mysqli_num_rows($res) == 1) {
  17.         echo "You have succesfully logged in.";
  18.         exit();
  19.     } else {
  20.         echo "Invalid login information. Please return the previous page";
  21.         exit();
  22.     }
  23. }
  24.  
  25. ?>
  26.  
  27.  
  28.  
  29. <!DOCTYPE html>
  30. <html>
  31. <head>
  32.     <title>Login</title>
  33. </head>
  34.  
  35. <body>
  36.     <form method="POST" action="login.php">
  37.         Username: <input type="text" name="username"></input>
  38.         Password: <input type="password" name="password"></input>
  39.         <input type="submit" name="submit" value="Log In"></input>
  40.     </form>
  41. </body>
  42. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement