I'm doing a search system where you have some fields (conditions) to search and find the results. These fields are not mandatory, in case the person type something he will find the data entered, in case the person does not type, the system will search all the data of the bank. The problem is that I use the following code:
<?php
$noiva_nome = @$_POST['noiva_nome'];
$noivo_nome = @$_POST['noivo_nome'];
$noiva_pai = @$_POST['noiva_pai'];
$noiva_mae = @$_POST['noiva_mae'];
$noivo_pai = @$_POST['noivo_pai'];
$noivo_mae = @$_POST['noivo_mae'];
$data = @$_POST['ano']."-".@$_POST['mes']."-".@$_POST['dia'];
$Query = mysql_query("SELECT * FROM noivos WHERE noiva_nome LIKE '%$noiva_nome%' OR noivo_nome LIKE '%$noivo_nome%' OR noiva_mae LIKE '%$noiva_mae%' OR noiva_pai LIKE '%$noiva_pai%' OR noivo_mae LIKE '%$noivo_mae%' OR noivo_pai LIKE '%$noivo_pai%' OR data LIKE '%$data%'");
This code, in case the user does not enter anything in the inputs it will do a search like 'bride_name LIKE' %% ', that is, empty and even then it will return the result because PHP finds results. The error is that sometimes the user even type the name of the bride for example, except that the other fields are empty, then it returns the result that has the name of the bride but also returns the other results nothing to see also, because of the inputs. Is there any way to get it fetched first by the results entered by the user and ignore the empty ones?