-1
I have a search system where I search users filtering by: name, age and email. If I filter by name and age and email, everything happens well, but if I filter only by age, for example, nothing is returned same try in the correct database. I think I’m doing it the wrong way, because I use the AND operator in the query, I mean, I want all three to return true, but that’s not really what I want. I want to filter by: age, or by age and email, or by age and email and name.
<?php
$nome = addslashes($_GET['nome']);
$idade = addslashes($_GET['idade']);
$email = addslashes($_GET['email']);
$sql = $pdo->query("SELECT * FROM usuarios WHERE nome = '$nome' AND idade = '$idade' AND email = '$email' ");
?>
You have to assemble querys to see if you receive null values in the parameters.
– Wesley Ferreira
You have to query separately for each situation.
– H C