php - How to correctly echo database results from checkbox form with submit button into table? -
hello i'm new php, mysql, , html , project i'm working on have simple database id, product, price, , condition. on html form have 4 checkboxes ranges of prices 0-25, 25-50, 50-75, , 75-100. here's example of i'm trying do: if user selects checkbox 0-25, it's supposed echo id, product, price, , condition of products cost 0-25 in table.i have checkbox values saved in array, i'm lost @ point. how can output values in database of checkbox checked.
p.s. i've heard of pdo, have use mysql project. here's html:
<form action="pricefilter.php" method="post"> <br><b>filter price:</b><br><br> <input type="checkbox" name="pricefilter[]" id="price" value="025"/> $0-$25<br><br> <input type="checkbox" name="pricefilter[]" id="price" value="2550"/> $25-$50<br><br> <input type="checkbox" name="pricefilter[]" id="price" value="5075"/> $50-$75<br><br> <input type="checkbox" name="pricefilter[]" id="price" value="75100"/> $75-$100<br><br> <input type="checkbox" name="pricefilter[]" id="price" value="100"/> $75-$100<br><br> <input type="submit" name="submit" value="submit" /> </form>
here php:
<?php mysql_connect ("localhost", "root","root") or die (mysql_error()); mysql_select_db ("xuswapsample"); $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); }
two things wrong in code
1) using post method submit form trying value using $_get, hence should use $_post
2) should use isset property of php check if values exist or not.
so solution try
if (isset($_post['pricefilter']) && ($_post['pricefilter']!="")) { $pricefilter = $_post['pricefilter']; // put remaining code here }