Advertisement
Guest User

Untitled

a guest
Apr 18th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.99 KB | None | 0 0
  1. <html>
  2.     <head>
  3.         <meta charset="utf-8">
  4.     </head>
  5.     <?php
  6.     if(isset($_POST['send']))
  7.     {
  8.         $servername = "localhost";
  9.         $username = "root";
  10.         $password = "";
  11.         $dbname = "maturitka";
  12.        
  13.         try {
  14.             $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
  15.             $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  16.             $stmt = $conn->prepare("SELECT id FROM user where login=:login and pass=:pass");
  17.             $stmt->bindParam(':login', $_POST['login']);
  18.             $stmt->bindParam(':pass', $_POST['pass']);
  19.             $stmt->execute();
  20.            
  21.             if($stmt->rowCount() > 0)
  22.             {
  23.                 echo "logged";
  24.             }
  25.             else
  26.             {
  27.                 echo "not logged";
  28.             }
  29.         }
  30.         catch(PDOException $e) {
  31.             echo "Error: " . $e->getMessage();
  32.         }
  33.         $conn = null;      
  34.     }
  35.     ?>
  36.     <body>
  37.         <form method="post" action>
  38.             <input type="text" name="login" placeholder="login">
  39.             <input type="text" name="pass" placeholder="pass">
  40.             <input type="submit" name="send" value="odeslat">
  41.         </form>
  42.     </body>
  43. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement