if( ($_POST['searchSubmit']) and ($_POST['destination_id'] or $_POST['region_id'] or $_POST['beds'] or $_POST['go2villa']) ){ $redirect = "http://thaivillagetaways.com/search/?"; $search = array("destination" => $_POST['destination_id'], "region" => $_POST['region_id'], "beds" => $_POST['beds'], "villa" => $_POST['go2villa']); foreach($search as $k => $v){ if($v){ if(!$count){ $redirect .= $k.'='.$v; $count=1; } else $redirect .= '&'.$k.'='.$v; } } header("location: $redirect"); }