I'm trying to make an empty select, which if not selected no option pulls all the results, using the AND in SELECT the form forces me to choose some option, how can I solve this? Here are the codes:
<form action="index2.php" method="post" >
<input type="hidden" name="submitted" value="true">
<label for="">Nome:
<input type="text" name="nome" />
</label>
<label for="">Tipo:
<select name="tipo" id="">
<option value=""></option>
<option value="P">Personagem</option>
<option value="R">Reino</option>
<option value="I">Item</option>
<option value="A">Ação</option>
</select>
</label>
<label for="">Vida:
<input type="text" name="vida">
</label>
<label for="">Força:
<input type="text" name="forca">
</label>
<input type="submit">
</form>
-
$nome = $_POST['nome'];
$tipo = $_POST['tipo'];
$vida = $_POST['vida'];
$forca = $_POST['forca'];
$query = "SELECT *
FROM WoH
WHERE NOME LIKE '%".$nome."%'
AND 'TIPO' = '$tipo'
AND 'VD' = '$vida'
";
Search does not work because it does not have any rows with "" value in my TYPE column. If I take the empty option, leaving the character option as default, it searches only the characters, how can I do it so that when the user wants to search the cards in ALL types, the default option brings me that result? p>