Error in SQL query with PDO

Asked

Viewed 178 times

-5

I can’t make the query, when I try to make it, I get the error:

Erro PDOStatement Object ( [queryString] => SELECT userid FROM usuario WHERE email=:email and senha=:senha )
<?php
require_once('conexao.php');
// @$email = $_POST['email'];
// @$senha = $_POST['senha'];
$email = "[email protected]";
$senha = "12346";

$pdo = $dbconn->prepare("SELECT userid FROM usuario WHERE email=:email and 
senha=:senha");
$pdo->bindParam("email", $email);
$pdo->bindParam("senha", $senha);
$pdo->execute();
print_r ($pdo);

$number = $pdo->fetchColumn();
// if($pdo->rowCount() == 1) {
//     $_SESSION['login'] = ['email'];

?>
  • 2

    Which error is giving? in reality you have to put the two points ":" in the parameter. $pdo->bindParam(":email", $email, PDO::PARAM_STR);&#xA;$pdo->bindParam(":senha", $senha, PDO::PARAM_STR);

  • Already tried, it returns this Pdostatement Object ( [queryString] => SELECT userid FROM user WHERE email=:email and password=:password )

  • Yes, that’s because you’re giving one print_r in the object $pdo, follow the flow that is to work yes

  • Okay, obg. I got it

1 answer

-1


Be able to solve

  require_once('conexao.php');
  // @$email = $_POST['email'];
  // @$senha = $_POST['senha'];
  $email = "[email protected]";
  $senha = "12346";

  $pdo = $dbconn->prepare("SELECT userid FROM usuario WHERE email=:email and 
  senha=:senha");
  $pdo->bindParam(":email", $email);
  $pdo->bindParam(":senha", $senha); 
  $pdo->execute();
  // print_r ($pdo);

  $query = $pdo->fetchAll(PDO::FETCH_ASSOC);
  print_r ($query);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.