Advertisement
Guest User

pdo

a guest
Mar 5th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.14 KB | None | 0 0
  1. <?php if (!empty($_POST)):?>
  2.             <?php
  3.                 $servername = "localhost:3307";
  4.                 $username = "root";
  5.                 $password = "usbw";
  6.  
  7.  
  8.                 try {
  9.                     $pu = $_POST["username"];
  10.                     $pp = $_POST["password"];
  11.                     $conn = new PDO("mysql:host=$servername;dbname=mydb", $username, $password);
  12.  
  13.                     $stmt = $conn->prepare("SELECT Password FROM Users WHERE username = :username");
  14.                     $stmt->bindParam(":username", $pu);
  15.                     $ran = $stmt->execute();
  16.                     if($ran){
  17.                         $val = $stmt->fetch();
  18.                         if($val["Password"] == $pp){
  19.                             $_SESSION["loggedin"] = 1;
  20.                             $_SESSION["username"] = $pu;
  21.                             header("Location: /index.php");
  22.                             die();
  23.                         }
  24.                     }
  25.  
  26.                 }catch(PDOException $e){
  27.                     echo "Connection failed: " . $e->getMessage();
  28.                 }
  29.  
  30.             ?>
  31.         <?php endif; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement