Codice PHP:
<?php
$query 
"SELECT * FROM viaggi where ";

if(isset(
$_POST['cognome']) and $_POST['cognome'] != ''){
      
$query .= "cognome = "'$_POST[cognome]'." and ";
    } 
if(isset(
$_POST['nome']) and $_POST['nome'] != ''){
      
$query .= "nome = "'$_POST[nome]'." and ";
    } 
if(isset(
$_POST['citta']) and $_POST['citta'] != ''){
      
$query .= "citta = "'$_POST[citta]'." and ";
    }
$result mysql_query($query);
                      while (
$row=mysql_fetch_array($result)) {
          
print 
$row['cognome'];
print 
$row['nome'];
print 
$row['citta'];
?>


<?php  ?>
Prova ma mi sa che ci vogliono anche altri controlli perché ti trovi con alla fine della query un AND seguito da niente.