Validate Login PHP PDO MYSQL

0

Hello, I'm starting with php already engaged in the PDO world and I have a question in my code

  

I want to check if the login exists and is the same one that was entered, if   for returns "existing login" if not "login not exist"

Most every time is returning false.

Example below

require_once("conexao.php");
$sql = $conn->query("SELECT nome, senha FROM login where nome=? and senha=?");
$resultado = $conn->prepare($sql);
$resultado->bindParam(1, $_POST['nome']);
$resultado->bindParam(2, $_POST['senha']);
$resultado->execute();
if($resultado->fetch(PDO::FETCH_ASSOC) == true):
echo"existe login";

else:
echo"não existe login";
endif;
  

Can someone help me by following the PDO rule and inform me   some examples with articles arguing about the subject.

    
asked by anonymous 27.06.2018 / 04:42

1 answer

0

It may be because of beginTransaction () and commit () . If it still is not, place a TryCatch and see if there is an error.

require_once("conexao.php");
$sql = $conn->query("SELECT nome, senha FROM login where nome=? and senha=?");
$conn->beginTransaction();
$resultado = $conn->prepare($sql);
$resultado->bindParam(1, $_POST['nome']);
$resultado->bindParam(2, $_POST['senha']);
$resultado->execute();
$con->commit();
if($resultado->fetch(PDO::FETCH_ASSOC) == true):
echo"existe login";

else:
$conn->rollBack();
echo"não existe login";
endif;
    
27.06.2018 / 05:36