Its a matter of building the WHERE conditions in the SQL query.
$query = "SELECT * FROM tablename WHERE $condition";
First you have to build $condition.
Simple case, 2 options, $fieldval1, $fieldval2, both text fields.
$condition = "";
if ($fieldval1 != "") $condition .= " field1 = '$fieldval1' ";
if ($condition != "") $condition .= " AND ";
if ($fieldval2 != "") $condition .= " field2 = '$fieldval2' ";
I admit it's not the most elegant coding but it should explain the principle.