0
My code below is working. However, note that I own the field CL_Cpf
and I need to add another that is CL_Cnpj
. Therefore, I need both to work in the same field input
and log in to the system.
How could I do that?
Code:
if(isset($_POST['documento']) && empty($_POST['documento']) == false) {
$documento = addslashes($_POST['documento']);
$email = addslashes($_POST['email']);
$dsn = "mysql:dbname=Provider;host=********l";
$dbuser = "root";
$dbpass = "*******";
try {
$db = new PDO($dsn, $dbuser, $dbpass);
$sql = $db->query("SELECT * FROM Provider.Cliente WHERE CL_Cpf = '$documento' AND CL_Email = '$email'");
if($sql->rowCount() > 0) {
$dado = $sql->fetch();
$_SESSION['documento'] = $dado['CL_Cpf'];
$_SESSION['email'] = $dado['CL_Email'];
header("Location: index.php");
}
} catch (PDOException $e) {
echo "Falhou: ".$e->getMessage();
}
}
?>
Why are there so many commas in your text? Wouldn’t it be simpler to use the correct punctuation to separate the prayers? As for the code, what do you have to say about the email? It seems to be a login field currently, but did not mention it in the question. It should be maintained or not?
– Woss
thanks for the reply Anderson, yes the email will be maintained, the login contains Cpf and email, however I want it to contain, Cpf, cnpj and email , when the person type Cpf or cnpj he will validate and log in the system
– J Junior Carneiro
https://answall.com/questions/297464/condi%C3%A7%C3%a3o-de-login-with-Usu%C3%a1rio-ou-e-mail-no-mesmo-campo
– Bacco
As @Andersoncarloswoss himself said... you can validate using OR, just taking care to validate what Cpf, cnpj or input email is...
''SELECT * FROM Provider.Cliente WHERE CL_Cpf = '$documento' OR CL_Email = '$email' OR CL_Cnpj = '$VAR'"
– Tadeu Mansi
@Reynaldomansi or a
WHERE '$documento' IN (CL_cpf, CL_cnpj)
(see my link above)– Bacco
@Bacco I think the option of
In
well even better and more practical, just wanted to illustrate theOU
as a matter of logic itself– Tadeu Mansi
@Reynaldomansi improved the response of the other link to cover the 2 situations
– Bacco
@Reynaldomansi and took the opportunity to make an alert for ( ), because the OR is a danger if the person does not know how to group. Imagine the disaster if the author doesn’t pay attention to it :D
– Bacco
Thank you very much ! it would be too much for me to ask how to make the correct select ? rsrs .. would be so ??
– J Junior Carneiro
$sql = $db->query("SELECT * FROM Provider.Client WHERE '$document' IN (Cl_cpf, Cl_cnpj) AND Cl_email = '$email'");
– J Junior Carneiro
didn’t work !!!
– J Junior Carneiro
ok solved this way $sql = $db->query("SELECT * FROM Provider.WHERE client (Cl_cpf= $document or Cl_cnpj= $document) AND Cl_email = '$email'");
– J Junior Carneiro