I want to fetch data from database on checkbox click,here my code works for single checkbox but it shows " mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in" error on multiple checkbox, Here is my Code,
if(isset($_POST['submit'])){
if(!empty($_POST['filter'])) {
$valid=true;
$filtering=$_POST['filter'];
$query_str=" WHERE ";
foreach ($filtering as $value){
if ($value=="Arsh Nagar"){
$query_str .="stylish_name='Arsh nagar'";
}
else if ($value=="Padma"){
$query_str .="stylish_name='Padma'";
}
else if ($value=="Kajal Yadav"){
$query_str .="stylish_name='Kajal Yadav'";
}
else if ($value=="Shweta"){
$query_str .="stylish_name='Shweta'";
}
else if ($value=="Harshil"){
$query_str .="stylish_name='Harshil'";
}
$query_str .=" OR ";
}
$query_str=substr($query_str,0,-5);
$sql="SELECT * FROM createdlook ".$query_str;
}
else{
$filter_err="Please Select atleast 1 stylish";
$valid=false;
}
}
if($valid)
{
$result=mysql_query($sql); //here is the error generated
$images = array();
$index = 0;
while($row = mysql_fetch_assoc($result)) // loop to give you the data in an associative array so you can use it however.
{
$images[$index] = $row;
$index++;
}
I think here is some query problem. please solve it if any error in the query