title: Search Form Ability To Ignore Blank Fields
body: <p>I have made a HTML search form which creates a query to a MySql database based on the contents of a form. What I would love to do is ignore the search parameter if the user leaves that specific form field empty. There are lots of answers online, especially on this website, but I can't get any of them to work.</p>
  
  <p>I have stripped down my code as much as possible to paste into here:</p>
  
  <p>The HTML input: </p>
  
  <pre><code>&lt;form action="deletesearchresults.php" method="GET"&gt;
    &lt;p&gt;&lt;b&gt;First Part Of Postcode&lt;/b&gt;
    &lt;input type="text" name="searchpostcode"&gt;&lt;/b&gt;  &lt;/p&gt;
    &lt;p&gt;&lt;b&gt;Category&lt;/b&gt;
      &lt;input type="text" name="searchfaroukcat"&gt;&lt;/b&gt;
  
  
      &lt;input type="submit" value="Search"&gt;
    &lt;/p&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>The PHP results display:</p>
  
  <pre><code>&lt;?php
      mysql_connect("myip", "my_username", "my_password") or die("Error connecting to database: ".mysql_error());
  
  
      mysql_select_db("my_db") or die(mysql_error());
  
  
  
     $sql = mysql_query("SELECT * FROM 
  GoogleBusinessData
  INNER JOIN TblPostcodeInfo ON GoogleBusinessData.BusPostalCode = TblPostcodeInfo.PostcodeFull WHERE PostcodeFirstPart = '$_GET[searchpostcode]' and FaroukCat = '$_GET[searchfaroukcat]' LIMIT 0,20");
  
  
     while($ser = mysql_fetch_array($sql)) {
  
        echo "&lt;p&gt;" . $ser['BusName'] . "&lt;/p&gt;";
        echo "&lt;p&gt;" . $ser['PostcodePostalTown'] . "&lt;/p&gt;";
        echo "&lt;p&gt;" . $ser['PostcodeArea'] . "&lt;/p&gt;";
        echo "&lt;p&gt;" . $ser['FaroukCat'] . "&lt;/p&gt;";
        echo "&lt;p&gt; --- &lt;/p&gt;";
  
  }
  
  ?&gt;
  </code></pre>
  
  <p>This works great until I leave one field blank, in which case it returns no results as it thinks I am asking for results where that field is empty or null, which I don't wat. I want all of the results where that form field is empty. </p>
  
  <p>I tried combining a like % [myfeild] % etc but I only want the results to display exactly what is on the field and not just the ones that contain what is in the field, for example searching for the postcode "TR1" would return results for TR1, TR10, TR11 etc. </p>
  
  <p>I believe I may need an array but after 3 days of trying, I just don't know how to get this done.</p>
  
  <p>Any help would be amazing. </p>
  
  <p>edit: Also, I will be adding up to ten fields to this form eventually and not just the two in this example so please bear this in mind with any suggestions you may have. </p>