title: I want to filter prices with checkboxes and php from a database
body: <p>I want to filter data on the database using a set of ranges. I have my checkbox down below. </p>
  
  <pre><code>&lt;body&gt;
  &lt;form id="form" method="post" action=""&gt;
  &lt;input type="checkbox" name="price1" class="checkbox" &lt;?=(isset($_POST['price'])?' checked':'')?&gt;/&gt; $0 - 5&lt;br&gt;
  &lt;input type="checkbox" name="price2" class="checkbox" &lt;?=(isset($_POST['price'])?' checked':'')?&gt;/&gt; $6 - 10&lt;br&gt;
  &lt;input type="checkbox" name="price3" class="checkbox" &lt;?=(isset($_POST['price'])?' checked':'')?&gt;/&gt; $11 - 20&lt;br&gt;
   &lt;/form&gt;
   &lt;/body&gt;
  
   &lt;script type="text/javascript"&gt;  
      $(function(){
       $('.checkbox').on('change',function(){
          $('#form').submit();
          });
      });
  &lt;/script&gt;
  </code></pre>
  
  <p>Below is what I have for my PHP code </p>
  
  <pre><code>&lt;?php
  if (isset($_POST["price1"])){
    $query = $conn-&gt;query("SELECT * FROM item WHERE price BETWEEN 0 AND 5");
   }
  
  if (isset($_POST["price2"])){
    $query = $conn-&gt;queryn("SELECT * FROM item WHERE price BETWEEN 6 AND 10");
   }
  
  if (isset($_POST["price3"])){
   $query = $conn-&gt;query("SELECT * FROM item WHERE price BETWEEN 11 AND 20");
   }
  
  else { $query = $conn-&gt;query("SELECT price * FROM item");
  }
  ?&gt;
  </code></pre>
  
  <p>Whenever I hit a checkbox mark it doesn't do anything it just shows a test Item I am pulling individually. The code below is just a test to make sure its pulling data from the database. Right now I am just pulling price ranges from 0 - 5 and it works. But the above code for the user to have a choice on selecting price ranges it wont do anything. Anything helps.  </p>
  
  <pre><code>?php
          //get product rows
          $query = $conn-&gt;query("SELECT * FROM item WHERE price BETWEEN 0 AND 5 ");
  
          if($query-&gt;num_rows &gt; 0){
                  while($row = $query-&gt;fetch_assoc()){
              ?&gt;
  
                  &lt;div class="list-item"&gt;
                      &lt;h2&gt;&lt;?php echo $row["name"]; ?&gt;&lt;/h2&gt;
                      &lt;h4&gt;Price: &lt;?php echo $row["price"]; ?&gt;&lt;/h4&gt;
                  &lt;/div&gt;
          &lt;?php }
          }else{
              echo  'Product(s) not found';
          } ?&gt;
      &lt;/div&gt;
  &lt;/div&gt; 
  </code></pre>
  
  <p>Code is below: </p>
  
  <pre><code>&lt;?php 
  $conn_error = "Could not connect";
  // SQL connection credentials
  
  //They are blanked out since it is connected to the server already
  
  $mysql_host = "";
  $mysql_user = "";
  $mysql_pass = "";
  $mysql_name = "";
  
  $conn = new mysqli($mysql_host, $mysql_user, $mysql_pass,$mysql_name);
  
  if ($db-&gt;connect_error) {
      die("Connection failed: " . $db-&gt;connect_error);
  }
  ?&gt;
  
  &lt;?php
          //get product rows test to see database is working 
          $query = $conn-&gt;query("SELECT * FROM item WHERE price BETWEEN 0 AND 5 ");
  
          if($query-&gt;num_rows &gt; 0){
                  while($row = $query-&gt;fetch_assoc()){
              ?&gt;
  
                  &lt;div class="list-item"&gt;
                      &lt;h2&gt;&lt;?php echo $row["name"]; ?&gt;&lt;/h2&gt;
                      &lt;h4&gt;Price: &lt;?php echo $row["price"]; ?&gt;&lt;/h4&gt;
                  &lt;/div&gt;
          &lt;?php }
          }else{
              echo  'Product(s) not found';
          } ?&gt;
      &lt;/div&gt;
  &lt;/div&gt; 
  
  &lt;body&gt;
  &lt;form id="form" method="post" action=""&gt;
  &lt;input type="checkbox" name="price1" class="checkbox" &lt;?=(isset($_POST['price'])?' checked':'')?&gt;/&gt; $0 - 5&lt;br&gt;
  &lt;input type="checkbox" name="price2" class="checkbox" &lt;?=(isset($_POST['price'])?' checked':'')?&gt;/&gt; $6 - 10&lt;br&gt;
  &lt;input type="checkbox" name="price3" class="checkbox" &lt;?=(isset($_POST['price'])?' checked':'')?&gt;/&gt; $11 - 20&lt;br&gt;
   &lt;/form&gt;
   &lt;/body&gt;
  
  &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.0/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
      $(function(){
          $('.checkbox').on('change',function(){
              $('#form').submit();
          });
      });
  &lt;/script&gt;
  &lt;?php
      if (isset($_POST["price1"])){
          $query = $conn-&gt;query("SELECT * FROM item WHERE price BETWEEN 0 AND 5");
  
      } elseif (isset($_POST["price2"])){
          $query = $conn-&gt;queryn("SELECT * FROM item WHERE price BETWEEN 6 AND 10");
      } elseif (isset($_POST["price3"])){
          $query = $conn-&gt;query("SELECT * FROM item WHERE price BETWEEN 11 AND 20");
      } else {
          $query = $conn-&gt;query("SELECT price * FROM item");
      }
  ?&gt;
  </code></pre>