title: Returning list of customers from user form defined values php/sql form
body: <p>Currently I am working on some code that would allow a user to enter in two values (in this case two zip codes) and when submitted, the program would return the values equal to and between the codes. For example, if 123456 and 234567 were entered as beginning and ending zip codes respectively, it would return customers with only zip codes in that range. </p>
  
  <p>I have been able to do this with SQL by hard coding in a pre determined range directly in the SQL command. But I would like to do this with the variables that the user enters. Which I am to believe that would be done in the final fetch command.</p>
  
  <pre><code>$SQL = "SELECT LastName, FirstName, Address1, City, State, Zip FROM Customers ORDER BY LastName ASC;";
  try {
      $sth = $conn-&gt;prepare($SQL);
      $sth-&gt;execute();
  } catch (PDOException $e) {
      echo "Error selecting customer records: " . $e-&gt;getMessage();
      die;
  }
  
  echo "Query excecuted successfully. &lt;br /&gt;";
  
  if($sth-&gt;rowCount()==0) {
      echo "No records returned. &lt;br /&gt;";
      die;
  } else {
      echo $sth-&gt;rowCount() . " records returned. &lt;br /&gt; &lt;br /&gt;";
  }
  
  while($result = $sth-&gt;fetch()){
      //in an array, refer to column with string inside brackets ['rid']
      echo "LastName: " . $result['LastName'] . "&lt;br /&gt;";
      echo "FirstName: " . $result['FirstName'] . "&lt;br /&gt;";
      echo "Address1: " . $result['Address1'] . "&lt;br /&gt;";
      echo "City: " . $result['City'] . "&lt;br /&gt;";
      echo "State: " . $result['State'] . "&lt;br /&gt;";
      echo "Zip: " . $result['Zip'] . "&lt;br /&gt; &lt;br /&gt;";
  }
  </code></pre>
  
  <p>In the initial $SQL statement I can use the WHERE Zip BETWEEN ## AND ## to get what I want, but I want to use the user defined variables. How would I go about that? I have looked quite extensively, but I must not be using the proper terms.</p>