How to not process an empty search request?

There is a search page

function find($name = '', $nm_nabor = '', $art = '', $factory = '')
{
    $db = mysql_connect("localhost", "****", "***");
    mysql_select_db("***", $db);
    mysql_query("SET NAMES 'utf8'");
    $result = mysql_query("SELECT * FROM arts WHERE productName LIKE '%$name%' AND collection LIKE '%$nm_nabor%' AND art LIKE '%$art%' AND factory LIKE '%$factory%' ", $db);
    if (!$result) {
        echo "       .     [email protected] <br> <strong> :</strong>";
        exit(mysql_error());
    }
    if (mysql_num_rows($result) > 0) {
        echo '<table width="0" border="1" cellpadding="2" cellspacing="0">';
        echo '<tr><td></td><td></td><td></td><td></td><td></td><td>      </td></tr>';
        while ($myrow = mysql_fetch_array($result)) {
            echo '<tr><td>' . $myrow['productName'] . '</td><td>' . $myrow['collection'] . '</td><td>' . $myrow['art'] . '</td><td>' . $myrow['factory'] . '</td><td>' . $myrow['price'] . '</td><td>' . $myrow['link'] . '</td></tr>';
        }
        echo '<table>';
    } else {
        echo '   !   .';
    }
}
function create_select()
{
    $db = mysql_connect("localhost", "amdstudiru_bot", "185800");
    mysql_select_db("amdstudiru_bot", $db);
    mysql_query("SET NAMES 'utf8'");
    $result = mysql_query("SELECT DISTINCT factory FROM arts", $db);
    if (!$result) {
        echo "       .     [email protected] <br> <strong> :</strong>";
        exit(mysql_error());
    }
    if (mysql_num_rows($result) > 0) {
        while ($myrow = mysql_fetch_array($result)) {
            echo '<option value="' . $myrow['factory'] . '">' . $myrow['factory'] . '</option>';
        }
    }
}
if ($_POST['status'] == "finding") {
    parse_str($_POST['param'], $output);
    $productName = $output['name'];
    $collection  = $output['name_nabor'];
    $art         = $output['art'];
    $factory     = $output['fabrica'];
    find($productName, $collection, $art, $factory);
}
if ($_POST['status'] == "spisok") {
    create_select();
}

What can I add so that an empty search request is not processed?


Answer 1

The search is done by the find function, so insert the condition:

if(!empty($productName) AND !empty($collection))
{
find($productName, $collection, $art, $factory); 
}
else
{
echo'  ';
}

In general, of course, it’s better not to do this, but since the whole search is done crookedly (this will be revealed a little later, when, for example, it will be necessary to display the search results page by page), such a solution would be quite appropriate.


Answer 2

What is an “empty” query? what fields must be left blank for the request to be considered empty?
You need to check these fields for emptiness before

$result = mysql_query("SELECT * FROM arts WHERE productName LIKE '%$name%' AND collection LIKE '%$nm_nabor%' AND art LIKE '%$art%' AND factory LIKE '%$factory%' ", $db);