Checkbox Form with Submit Button doesn't echo values from database php html sql -


i'm new php, html, , mysql. have database username, product, , price want sell product for. code checkbox form submit button works price filter, when submitted it's supposed echo username, product, , price matches corresponding checkbox. . if user selects checkbox labeled, "0-25" or "100 & above", , clicks submit button supposed echo users have items in specific price range. i've looked online tried manipulate close have. please me out or give me insight on how this? appreciated

here checkbox form.

<form action="pricefilter.php" method="post">     <br><b>filter price:</b><br><br>      <input type="checkbox" name="$0-$25[]" id="price" value="0-25"/>&nbsp;$0-$25<br><br>     <input type="checkbox" name="$25-$50[]" id="price" value="25-50"/>&nbsp;$25-$50<br><br>     <input type="checkbox" name="$50-$100[]" id="price" value="50-100"/>&nbsp;$50-$100<br><br>     <input type="submit" name="submit" value="submit" /> </form> 

here code php file.

<?php mysql_connect ("localhost", "root","root")  or die (mysql_error()); mysql_select_db ("xuswapuser");  $pricefilter = $_get['pricefilter'];   $filteredresponse = array (); foreach($pricefilter $range) { if($range == 025)     {         $query = "select * books price <= 25";         $sql = mysql_query($query);          array_push($filteredresponse, $sql);        }      if($range == 2550)     {         $query = "select * books price >= 25 , price <=50";         $sql = mysql_query($query);          array_push($filteredresponse, $sql);     }      if($range == 5075)     {         $query = "select * books price >= 50 , price <=75";         $sql = mysql_query($query);          array_push($filteredresponse, $sql);     }       if($range == 75100)     {         $query = "select * books price >= 75 , price <=100";         $sql = mysql_query($query);          array_push($filteredresponse, $sql);     }      if($range == 100)     {         $query = "select * books price >= 100";         $sql = mysql_query($query);          array_push($filteredresponse, $sql);     }  }  ?>    <html>    <head>    <title>  xuswap  </title> <script type="text/javascript" src="sorttable.js"></script> </head> <body style="margin: 0; padding: 0;">        <div id="header" style="background-color:#339900;height:157px;width:100%;position:relative;">                                      <!--header area-->             <form id="headerform" name="headerform" method="post" action="" align="right">                   <input type="image" src="https://encrypted-tbn0.gstatic.com/images?q=tbn:and9gcsn3xiae50cjq5cf91gbaywpkchmi5hoaqyxgmrn8f5ohw7i_rt5q" alt="placeholder" align="left" width="150" height="150">                   <br><br><br>                   <input type="text" name="searchinput"id="search" style="width:500px;"/>                   <input type="submit" name="searchbutton" id="searchbutton" value="search" />                   <input type="submit" name="logoutbutton" id="logoutbutton" value="logout"/>                   <br><br><br>              </form>        </div>         <div id="background" style="background-color:#ffd700;height:100%; width:100%;">   <div id = "pagecontent"></div>  <div id="background" style="background-color:#ffd700;height:100%; width:100%;">  <blockquote>     <blockquote>       <blockquote>         <blockquote>           <blockquote>             <blockquote>               <blockquote>                 <p>books </p>               </blockquote>             </blockquote>           </blockquote>         </blockquote>       </blockquote>     </blockquote>   </blockquote>         <blockquote>                                  <table class="sortable" width="940" height="52" border="0">                                 <tr>                                   <td width="200" id="sortable">username</td>                                   <td width="253"> product</td>                                   <td width="220">condition</td>                                   <td width="249">price</td>                                 </tr>                                 <?php { ?>                                   <tr>                                     <td><?php echo $range['id']; ?></td>                                     <td><?php echo $range['product']; ?></td>                                     <td><?php echo $range['condition']; ?></td>                                     <td><?php echo $range['price']; ?></td>                                   </tr>                                   <?php } while ($range = mysql_fetch_assoc($sql)); ?>                               </table> 

this simple code follow, can loop through possibilities putting checked values array , performing query through foreach()

<input type="checkbox" name="pricefilter[]" value="025"> <input type="checkbox" name="pricefilter[]" value="2550"> // etc.  <?php   $pricefilter = $_post['pricfilter']; // array    if(isset($pricefilter[025]))   {       $query25 = "select * books price <= 25";   }   if(isset($pricefilter[2550]))   {       $query2550 = "select * books price >= 25 , price <= 50";   }   //etc.    // run query if set    if(isset($query25))   {       $sql = mysql_query($query25);   }    // w/e need run subsequent possibily ?> 

this time consuming trying point across on how handle checkboxes in php

update if want foreach:

<?php $pricefilter = $_get['pricefilter']; $filteredresponse = array (); foreach($pricefilter $range) { if($range == 025)     {         $query = "select * books price <= 25";         $sql = mysql_query($query);          array_push($filteredresponse, $sql);     }      if($range == 2550)     {         $query = "select * books price >= 25 , price <=50";         $sql = mysql_query($query);          array_push($filteredresponse, $sql);     }      // conditions , can save results in array of arrays } 

you have array of mysql responses based on selections checkbox form. parse information see fit.

i suggest - before moving forward use pdo instead of mysql_ legacy code

take gander @ pdo use


Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -