title: Retrieve Columns from SQL Database Table Based on User Input in HTML Form
body: <p>I apologize if this has been covered before. I looked at all of the suggestions and nothing seems to fit what I need here.</p>
  
  <p>In any event, I am trying to develop an auto parts bank where the following information is stored in a table called "auto_parts":</p>
  
  <ul>
  <li>Distributor</li>
  <li>Address</li>
  <li>City</li>
  <li>State</li>
  <li>Zip</li>
  <li>Phone Number</li>
  <li>SKU</li>
  <li>Part</li>
  <li>New or Used</li>
  <li>Year</li>
  <li>Make / Model</li>
  <li>Price</li>
  </ul>
  
  <p><a href="http://i.stack.imgur.com/YLd4Y.png" rel="nofollow">The table looks like this:</a></p>
  
  <p>I want customers to be able to submit a form that asks them the following questions:</p>
  
  <p>City, State, Part, New or Used, Year, and Make / Model,</p>
  
  <p>which would query my database and output <strong>all of the information</strong> on the table column that meets the previous criteria:</p>
  
  <p><strong>Query Output:</strong></p>
  
  <ul>
  <li>Distributor</li>
  <li>Address</li>
  <li>City</li>
  <li>State</li>
  <li>Zip</li>
  <li>Phone Number</li>
  <li>SKU</li>
  <li>Part</li>
  <li>New or Used</li>
  <li>Price</li>
  </ul>
  
  <p>Here is an abbreviated version of my form:</p>
  
  <pre><code>&lt;form action="parts_query.php" method="get"&gt;
  &lt;h2 align="center"&gt;Find Auto Part&lt;/h2&gt;
  &lt;strong&gt;City:&lt;/strong&gt; 
  &lt;br /&gt;
  &lt;input type="text" name="City" value="City" required&gt;
  &lt;br /&gt;
  &lt;strong&gt;State:&lt;/strong&gt; 
  &lt;br /&gt;
  &lt;select name="State" size="1" required&gt;&lt;option selected="selected"&gt;Choose One:
  &lt;option&gt;AL
  &lt;option&gt;AK
  &lt;option&gt;AZ
  &lt;option&gt;AR
  &lt;option&gt;CA
  &lt;option&gt;...
  &lt;/select&gt;
  &lt;br /&gt;
  &lt;strong&gt;Select Part:&lt;/strong&gt;
  &lt;br /&gt;
  &lt;select name="Part" size="1" required&gt;&lt;option selected="selected"&gt;Choose One:
  &lt;option&gt;A Pillar
  &lt;option&gt;A/C Compressor
  &lt;option&gt;A/C Compressor Clutch Only
  &lt;option&gt;A/C Condenser
  &lt;option&gt;A/C Condenser Fan
  &lt;option&gt;A/C Control Computer
  &lt;option&gt;A/C Evaporator
  &lt;option&gt;A/C Evaporator Housing only
  &lt;option&gt;A/C Heater Control (see also Radio or TV Screen)
  &lt;option&gt;A/C Hose
  &lt;option&gt;Accelerator Parts
  &lt;option&gt;Adaptive Cruise Projector
  &lt;option&gt;...
  &lt;/select&gt;
  &lt;br /&gt;
  &lt;strong&gt;New or Used?&lt;/strong&gt;
  &lt;br /&gt;
  &lt;select name="New_Used" size="1"&gt;&lt;option selected="selected"&gt;Choose One:
  &lt;option&gt;New
  &lt;option&gt;Used
  &lt;/select&gt;
  
  &lt;br /&gt;
  &lt;strong&gt;Vehicle Year:&lt;/strong&gt; 
  &lt;br /&gt;  
  &lt;select name="Year" required&gt;&lt;option selected="selected"&gt;Choose One:
  &lt;option value="2016"&gt;2016&lt;/option&gt;
  &lt;option value="2015"&gt;2015&lt;/option&gt;
  &lt;option value="2014"&gt;2014&lt;/option&gt;
  &lt;option value="2013"&gt;2013&lt;/option&gt;
  &lt;option value="2012"&gt;2012&lt;/option&gt;
  &lt;/select&gt;
  &lt;br /&gt;
  
  &lt;strong&gt;Vehicle Make / Model:&lt;/strong&gt;&lt;br /&gt; 
  &lt;select name="Make_Model" required&gt;&lt;option selected="selected"&gt;Choose One:
  &lt;option&gt;AMC Ambassador
  &lt;option&gt;AMC American
  &lt;option&gt;AMC AMX
  &lt;option&gt;...
  &lt;/select&gt;
  &lt;br /&gt;
  &lt;br /&gt;
  &lt;input class="btn" type="submit" value="Submit"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>I have tried numerous variations of queries to search my database table for the above information submitted via my form, then output all relevant information (as outlined above) to an HTML table, but nothing seems to work. I am still pretty new to working with databases and again I apologize if my question seems redundant or overly broad.</p>
  
  <p>I don't remember how parts_query.php originally looked because I've been changing it a lot, but what I have now looks like this: </p>
  
  <pre><code>    &lt;?php
  //Connecting to sql db.
  $connect = mysqli_connect("localhost","root","","autoparts_bank");
  
  $query = "SELECT * FROM auto_parts WHERE City = [] AND Part = [] AND Year = [] AND Make_Model = []"
  $result = mysql_query($query);
  
  echo "&lt;table&gt;"; // start a table tag in the HTML
  
  while($row = mysql_fetch_array($result)){   //Creates a loop to loop through results
  echo "&lt;tr&gt;
  &lt;td&gt;" . $row['Distributor'] . "&lt;/td&gt;
  &lt;td&gt;" . $row['Address'] . "&lt;/td&gt;
  &lt;td&gt;" . $row['City'] . "&lt;/td&gt;
  &lt;td&gt;" . $row['State'] . "&lt;/td&gt;
  &lt;td&gt;" . $row['Zip'] . "&lt;/td&gt;
  &lt;td&gt;" . $row['Phone'] . "&lt;/td&gt;
  &lt;td&gt;" . $row['Part'] . "&lt;/td&gt;
  &lt;td&gt;" . $row['New_Used'] . "&lt;/td&gt;
  &lt;td&gt;" . $row['Price'] . "&lt;/td&gt;
  &lt;/tr&gt;";  //$row['index'] the index here is a field name
  }
  
  echo "&lt;/table&gt;"; 
  
  mysql_close(); //Make sure to close out the database connection
  ?&gt;
  
  &lt;?php
  //Connecting to sql db.
  $connect = mysqli_connect("localhost","root","","autoparts_bank");
  //Sending form data to sql db.
  mysqli_query($connect,"INSERT INTO `auto_parts` (`Distributor`, `Address`, `City`, `State`, `Zip`, `Phone_No`, `SKU`, `Part`, `New_Used`, `Year`, `Make_Model`, `Price`) 
  VALUES ('$_POST[Distributor]', '$_POST[Address]', '$_POST[City]', '$_POST[State]', '$_POST[Zip]', '$_POST[Phone_No]', '$_POST[SKU]', '$_POST[Part]', '$_POST[New_Used]', '$_POST[Year]', '$_POST[Make_Model]', '$_POST[Price]')");
  ?&gt;
  </code></pre>