Below is my script that is executed when a user enters information into a search bar and hits the submit button. I keep getting the error "Warning: mysqli_stmt_bind_param(): Number of variables doesn't match number of parameters in prepared statement". The number of variables and values is equal, yet I keep getting this error. Any help would be greatly appreciated, thank you!
I have also included an image of my current database table here
include_once 'dbh-inc.php';
if (isset($_POST['submit-search'])) {
$search = $_POST['search'];
$sql = "SELECT * FROM animals WHERE animal_animaltype LIKE '%?%' OR animal_breed LIKE '%?%' OR descGallery LIKE '%?%'";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql)) {
echo "SQL error";
} else {
mysqli_stmt_bind_param($stmt, "sss", $search, $search, $search);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
$resultCount = mysqli_num_rows($result);
if ($resultCount > 0) {
echo "There are ".$resultCount." results for your search";
while ($row = mysqli_fetch_assoc($result)) {
echo '<a href="#">
<div style="background-image: url(img/gallery/'.$row["imgFullNameGallery"].');"></div>
<h3>'.$row["animal_name"].'</h3>
<h3>'.$row["animal_breed"].'</h3>
<p>'.$row["descGallery"].'</p>
<br>
<h1>'.'Current owner: '.$row["animal_owner"].'</h1>
</a>';
}
}
}
}