-2
So guys I’m having a hard time in a part of my code, as it is too big I will post only the part that is wrong:
<?php
try{
$entrar = $_POST["entrar"];
$cpf = $_POST["cpf"];
$senha = $_POST["senha"];
/*Conexão com o banco de dados*/
$pdo = new pdo('tipo_do_banco:host=servidor;dbname=nome_do_banco','nome_do_usuário','senha_do_usuario');
$pdo->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
/*Verificando se o usuário existe na tabela já*/
var_dump($entrar);
if($entrar==true){
$validacao = $pdo->prepare('SELECT * FROM aluno WHERE cpf = :cpf AND senha = :senha LIMIT 1');
$validacao ->bindValue('nome'); (não sei se está certo, queria pegar o nome do cara da tabela sql)
$validacao ->bindParam(":cpf",$cpf,PDO::PARAM_STR);
$validacao ->bindParam(":senha",$senha ,PDO::PARAM_STR);
$validacao ->execute();
/*Se a validação achar algo, vai direto para área do aluno*/
$retorno = $validacao->FetchAll();
if(count($retorno)>= 1){
$_SESSION['nome'] = $nome;
$_SESSION["cpf"] = $cpf;
$_SESSION["senha"] = $senha;
header('Location: alguma-area.php');
exit();
}else{
unset ($_SESSION["cpf"]);
unset ($_SESSION["senha"]);
echo('Cpf ou senha inválidos');
}
}
}catch(PDOException $error){
echo 'Error: ' . $error->getMessage();
}
?>
This IF does not execute, locking all other commands (has more code).
I would also like to know if it is possible through this select to get the name of the right table guy, how would it be done? Maybe using $validacao->bindValue('id');
Just before the if line do a var_dump($login) and post here the result
– Ademilson Santana da Silva
It was NULL when I did it, but I’m passing normally. Look at this... <input type="Submit" id="enter" name="enter" value="enter"> $enter = $_POST["enter"]; var_dump($enter); if($enter==true){
– user124232
Do you declare $enter somewhere? maybe initialize it with false!
– anderson seibert
So there’s the problem.. edit the question showing the part of the code where you assign a value to the $enter variable
– Ademilson Santana da Silva
Yes, after the html form Ubmit, I open <?php and declare it $enter = $_POST["enter"];
– user124232
check if the input of html is with the attribute name.
– Ademilson Santana da Silva
create a <input type="text" name="enter" value="Enter"> and delete the attribute name of the button, then in PHP make $enter = isset($_POST['enter'])
– Ademilson Santana da Silva
Well, it gave the bool value (false, for not being clicked), but lost the Submit to turn true and send the information...
– user124232
Before if(Count... puts
print_r($validacao->errorInfo())
– adventistaam
Substitution
new pdo
fornew PDO
– adventistaam
-advantisaam, I did this, but it does not understand the if function at the time of giving TRUE and does not return error or anything
– user124232
Before that line
$retorno = $validacao->FetchAll();
giveprint_r($validacao->errorInfo())
– adventistaam
Guys, thanks for your help, I’ll close the topic =)
– user124232