Omegq

Php database connection error

May 29th, 2023
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.24 KB | None | 0 0
  1.             $email = filter_input(INPUT_POST,"email");
  2.             $password = password_hash(filter_input(INPUT_POST, "password"), PASSWORD_DEFAULT);
  3.            
  4.             if(isset($_POST['signup'])){
  5.                 $con = new PDO('mysql:host=localhost; dbname=abc', 'root', '');
  6.                 $con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  7.                 $stmt = $con->prepare('INSERT INTO users VALUES (null, ?, ?)');
  8.                 $result = $stmt->execute(array($email, $password));
  9.             }
  10.  
  11.             else{
  12.                 $con = new PDO('mysql:host=localhost; dbname=abc', 'root', '');
  13.                 $con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  14.                
  15.                 //$dbp = "";
  16.  
  17.                 $stmt = $con->prepare('SELECT password FROM users WHERE password=? AND email=?');
  18.                 $stmt->execute(array($password, $email));
  19.                 $result = $stmt->fetchAll();
  20.  
  21.  
  22.                 echo gettype($result);
  23.                 echo sizeof($result);
  24.                
  25.                 if($result){
  26.                     echo "Signed in, Welcome!";
  27.                 }
  28.                 else{
  29.                     echo "Username or password problem, try again later";
  30.                 }
Tags: sql php coding
Advertisement
Add Comment
Please, Sign In to add comment