Two things. They both deal with this bit of code:
if(!$result){
echo 'Error in Search for Results:'.mysql_error();
exit();
}
Are you sure you want exit()? To stop processing the entire script? If you instead used return, i.e. 'return 0;' you could stop processing the rest of the function. I don't know how your script is set up, just a bit of info.
Secondly, are you saying that if no results are returned, this bit of code isn't stopping the function? Because if that's what you're saying, then you need to modify the code a bit. $result will only be FALSE if there was an error running the query. A query can run successfully even if no results are returned. Try this bit of code:
if(!$result || @mysql_num_rows($result) == 0){
echo 'Error in Search for Results:'.mysql_error();
exit();
}
This probably isn't the best way (using the error surpressor), but it should still get the job done. Give it a try and let us know.