Advertisement
Guest User

dbConnecterController.php

a guest
Mar 31st, 2016
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.38 KB | None | 0 0
  1. <?php
  2. namespace App\Controller;
  3. use PDO;
  4.  
  5. class dbConnecterController {
  6.     public function __construct(){
  7.     }
  8.  
  9.     public  function validate(){
  10.  
  11.         $username = $_POST['username'];
  12.         $password = $_POST['password'];
  13.  
  14.         $host = "localhost";
  15.         $user = "root";
  16.         $pass = "";
  17.         //$pass = "toor";
  18.         $dbname = "MyGalleryDb";
  19.         //$dbname = "mygallerydb";
  20.  
  21.  
  22.         // Handle a bit of connection errors
  23.         try {
  24.             // Connect to server via PHP Data Object
  25.             $dbconnection = new PDO('mysql:host='.$host.';dbname=' . $dbname, $user, $pass);
  26.  
  27.  
  28.  
  29.         } catch (PDOException $e) {
  30.             echo htmlentities($e);
  31.             die();
  32.             echo "FAIL!";
  33.         }
  34.  
  35.             $result = $dbconnection->query('SELECT * FROM users WHERE username="'.$username.'" && password ="'.$password.'";');
  36.             $result->setFetchMode(PDO::FETCH_ASSOC);
  37.             //$row = $result->fetch();
  38.  
  39.             if ($username && $password) {
  40.                 $row = $result->fetchColumn();
  41.                 if($row != 0){
  42.                     while ($result->fetchColumn) {
  43.                         $usernameDb = $info['username'];
  44.                         $passwordDb = $info['password'];
  45.  
  46.                         if ($username == $usernameDb && $password == $passwordDb) {
  47.                             header('Location: gallery.php');
  48.                             $_SESSION['username'] = $usernameDb;
  49.                         } else {
  50.                             die("You messed up maaan... Check your username or password.");
  51.                         }
  52.                     }
  53.                 } else {
  54.                     die("Username not in the DB, talk with the owner to add you!");
  55.                 }
  56.             }
  57. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement