I have this code for simple advanced search form, i spent hours tying to figure this out i couldn't ..
//==============connect============//
$mysqli = new mysqli("localhost", "root", "AWAAWA@19", "SDE");
//==============connect============//
$nationality=$_POST['nationality'];
$birthplace=$_POST['birthplace'];
$dob=$_POST['dob'];
$study=$_POST['study'];
$status=$_POST['status'];
$kids=$_POST['kids'];
$smoking=$_POST['smoking'];
$covered=$_POST['covered'];
$hobbies=$_POST['hobbies'];
//============ For Pagination ============
$where .= "nationality LIKE ?";
$params[] = $nationality;
$type_string .="s";
if(empty($birthplace)){
$where .= " and birthplace LIKE ?";
$params[] = $birthplace;
$type_string .="s";
}
if(isset($dob)){
$where .= " and dob LIKE ?";
$params[] = $dob;
$type_string .="s";
}
if(isset($study)){
$where .= " and study LIKE ?";
$params[] = $study;
$type_string .="s";
}
if(isset($status)){
$where .= " and status LIKE ?";
$params[] = $status;
$type_string .="s";
}
if(isset($kids)){
$where .= " and kids LIKE ?";
$params[] = $kids;
$type_string .="s";
}
if(isset($smoking)){
$where .= " and smoking LIKE ?";
$params[] = $smoking;
$type_string .="s";
}
if(isset($covered)){
$where .= " and covered LIKE ?";
$params[] = $covered;
$type_string .="s";
}
if(isset($hobbies)){
$where .= " and hobbies LIKE ?";
$params[] = $hobbies;
$type_string .="s";
}
$from_section = 'app_female';
$sql_search= "SELECT id,name,nationality,birthplace,status,study
FROM $from_section
where $where
order by id desc";
$stmt_search = mysqli_stmt_init ($mysqli);
if (!mysqli_stmt_prepare($stmt_search,$sql_search)) {
printf("Error: %s.\n", $stmt_search->error);
}
else {
mysqli_stmt_bind_param($stmt_search,$type_string, ...$params);
mysqli_stmt_execute($stmt_search);
mysqli_stmt_store_result($stmt_search);
mysqli_stmt_bind_result($stmt_search, $id,$name,$nationality,$birthplace,$status,$study);
echo $count_search = mysqli_stmt_num_rows($stmt_search);
}
mysqli_close($mysqli);
it always returns 0 even tho i have records in database matches the given search terms.. what am i doing wrong here? i used the code on a previous project and now it doesn't work or am i missing something?