Вы можете поместить значения для ваших заполнителей в переменную массива. А в mysqli_stmt_bind_param () вы можете использовать оператор splat ...
- как в приведенном ниже коде, чтобы вы могли обрабатывать различное количество заполнителей и его значений для одного поля таблицы.
Вы можете сделать что-то вроде этого:
$interest_array = array('basketball', 'basketball', 'basketball', 'basketball');
$s_marks = str_repeat("s", count($interest_array));
mysqli_stmt_bind_param($stmt, $s_marks, ...$interest_array);
Это:
mysqli_stmt_bind_param($stmt, $s_marks, ...$interest_array);
Будет рассматриваться как:
mysqli_stmt_bind_param($stmt, "ssss", $interest1,$interest2,$interest13, $interest4);
Ваш обновленный код (еще не проверен):
$Interest = $_GET['interestId'];
$sql = "SELECT * from User WHERE (Interest1 = ? OR Interest2 = ? OR Interest3 = ?) OR ? = 'Any Interest';";
$placeholder_count = substr_count($sql, '?');
$s_marks = str_repeat("s", $placeholder_count); // creates sss string
$interest_array = array_fill(0, $placeholder_count, $Interest); // creates an array of the same values.
echo "<h1 class='contact-intro'>";
echo " Welcome to the business card library for $Interest! </h1>";
$stmt = mysqli_stmt_init($link);
if (!mysqli_stmt_prepare($stmt, $sql)) {
echo "SQL statement failed";
} else {
mysqli_stmt_bind_param($stmt, $s_marks, ...$interest_array);
mysqli_stmt_execute($stmt);
}
Остальная часть кода будет применяться в зависимости только от количества заполнителя в строке sql.