title: Running a query with missing variables
body: <p>This script is selecting data based on optional fields in a HTML form. Although they are optional fields, at least 1 must be entered with the idea being that the more fields entered, the more likely you are to get a single result. For test I have two records with the same first and last name but different ID's and mobile numbers. At the moment when entering a name, 2 fields are given... Correct but when entering a mobile or ID, two results are still displayed.</p>
  
  <p>Ive tried reading into passing missing variables in an SQL query but haven't got very far. Anything blindingly obviously wrong?</p>
  
  <p>Thanks</p>
  
  <pre><code>&lt;?php
  
  include "checkmysqlconnect.php";
  
  $firstname = $_POST['firstname'];
  $lastname = $_POST['lastname'];
  $mobile = $_POST['mobile'];
  $attendid = $_POST['attendid'];
  $search = $_POST['search'];
  
  if ($search == "Search") {
  if ($firstname == '' AND $lastname == '' AND $attendid == '' AND $mobile == '') {
      header("Location: searchattendform.php?result=1");
          $error = true;
      }
  
      if($error != true) {
  
  $sql = "SELECT * FROM `attend` WHERE `firstname` = '".$firstname."' AND `lastname` = '".$lastname."' AND `attendid` = '".$attendid."' AND `mobile` = '".$mobile."'";
  $query = mysql_query($sql);
  $count = mysql_num_rows($query);
  
  if ($count &gt; 1) {
  while($value = mysql_fetch_assoc($query)) {
      echo "More than one attendee with this name. Entering more details will help narrow down results.";
      echo "&lt;tr&gt;&lt;td&gt;".$value['attendid']."&lt;/td&gt;&lt;td&gt;".$value['wristband']."&lt;/td&gt;&lt;td&gt;".$value['firstname']."&lt;/td&gt;&lt;td&gt;".$value['lastname']."&lt;/td&gt;&lt;td&gt;".$value['telephone']."&lt;/td&gt;&lt;td&gt;".$value['mobile']."&lt;/td&gt;&lt;td&gt;".$value['address1']."&lt;/td&gt;&lt;td&gt;".$value['address2']."&lt;/td&gt;&lt;td&gt;".$value['town']."&lt;/td&gt;&lt;td&gt;".$value['postcode']."&lt;/td&gt;&lt;td&gt;".$value['email']."&lt;/td&gt;&lt;td&gt;".$value['medical']."&lt;/td&gt;&lt;/tr&gt;";
  } } else {
  if ($count == 0) {
      header("Location: searchattendform.php?result=2");
  } else {
      if ($count == 1) {
          ($value = mysql_fetch_assoc($query));
          echo "&lt;tr&gt;&lt;td&gt;".$value['attendid']."&lt;/td&gt;&lt;td&gt;".$value['wristband']."&lt;/td&gt;&lt;td&gt;".$value['firstname']."&lt;/td&gt;&lt;td&gt;".$value['lastname']."&lt;/td&gt;&lt;td&gt;".$value['telephone']."&lt;/td&gt;&lt;td&gt;".$value['mobile']."&lt;/td&gt;&lt;td&gt;".$value['address1']."&lt;/td&gt;&lt;td&gt;".$value['address2']."&lt;/td&gt;&lt;td&gt;".$value['town']."&lt;/td&gt;&lt;td&gt;".$value['postcode']."&lt;/td&gt;&lt;td&gt;".$value['email']."&lt;/td&gt;&lt;td&gt;".$value['medical']."&lt;/td&gt;&lt;/tr&gt;";
      } else {
          echo "The was an issue searching attendees. Please contact SOFia Admin.";
          } }
  }
  }
  }
  
  ?&gt;
  </code></pre>