3
I am migrating my php code in which I was using sql query to PDO, but I am finding it difficult to validate data with this.
NOTE:I already have a functional file that does the search in the database, my difficulty is really in comparing it with the POST and validate them.
OBS2: If someone can give me some link to help in the migration of mysql_ to PDO would help too!
Follow the php code I’m trying to make work:
if(isset($_POST['entrar']) && $_POST['entrar'] == "login"){
$ID = $_POST['usuario'];
$senha = $_POST ['senha'];
if (empty($ID) || empty ($senha)){
echo '<p style="font: 20px Verdana; position:absolute; top:700px; left:40%; color:red;">Por favor preencha os campos!</p>';
}
else{
$buscar=$pdo->prepare("SELECT ID, senha, usuario FROM usuarios WHERE ID='$ID' AND senha='$senha'");
$buscar->execute();
$linha=$buscar->fetchALL(PDO::FETCH_ASSOC);
foreach ($linha as $listar){
if ($listar >0){
$_SESSION['ID'] = $busca ['ID'];
$_SESSION['usuario'] = $busca ['usuario'];
header ('location:logado.php');
exit;
}
else{
echo '<p style="font: 30px Verdana; text-align:center; color:red;">Usuario ou senha invalidos.';
echo '<meta http-equiv="refresh" content="1;URL=index.html" />';
}
}
}
What’s the problem? when doing tests can comment on
header()
code to view error messages.– rray
$listar
comes from where?– rray
My mistake, corrected it. The problem is in if probably, I am not knowing how to compare it to make this validation successfully, I changed only a little compared to the code using sql_.
– Wel