使用REGEXP搜索三个字段并避免空子字符串错误

I have one search form that searches database fields 'name' and 'address', and a drop down list that searches the database field 'type' and displays the results in a search_results.php page. My basic aim is to search the name and address fields for, say, 'dune', and have results that match any word that contains 'dune' in it, for example a search for 'dune' returns results such as 'binedune', 'countdune', 'sanddune' etc.

Also, if the search returns an empty result especially when using the drop down list, I do not want the 'empty substring' error appearing. Take for example the 'type' column for the 'markers' table in the database contains the fields 'New York','Munich','London' and 'Nairobi'. This are the same list options displayed in the dropdown list, in addition to other cities like 'New Jersey','Cairo' etc. When I select, for example, 'Cairo', it makes a search in the database but does not find Cairo and returns the error 'Got error empty (sub)expression'.

This is what I have so far:

page name: search_results.php

<?PHP
//include db connection and functions file
require_once("lib/db.php");
require_once("lib/functions.php");

//Get POST vars from search form and drop down list

$name = "";
if(!empty($_POST['name'])){
    $name = mysql_real_escape_string(trim($_POST['name']));
}

if(!empty($_POST['address'])){
    $address = mysql_real_escape_string(trim($_POST['address']));
}

$type = "";
if(!empty($_POST['type'])){
    $type = mysql_real_escape_string(trim($_POST['type']));
}

//search form here. It redirects to this page, same as the drop down list which uses javascript to post vars to this same page

//This is the SQL query that is giving me the nightmares

$query="SELECT * FROM markers WHERE name REGEXP '^(".$name.")' OR address REGEXP '^(".$address.")' OR type REGEXP '^(".$type.")' AND active = 1";

$result=mysql_query($query) or die(mysql_error());
//display results here

The problem is that if there is no match to 'type' in the database, I get the error Got error 'empty (sub)expression. Any assistance would be appreciated