Ваша команда mysqli_query будет возвращать false. Используйте mysqli_error для диагностики проблемы.
if (!mysqli_query($link, $query)) {
printf("Errormessage: %s\n", mysqli_error($link));
}
Вам потребуется выполнить вышеуказанную проверку, чтобы определить наверняка, но проблема с вашим запросом может быть связана с этим разделом, в котором нет кавычек в виде строкового значения:
if ($form_member_name !=0) {
$query .= "AND members.member_name = $form_member_name ";
}
$ form_member_name должно быть как минимум заключено в одинарные кавычки, но вы должны определенно использовать параметризованные операторы для этого, а не встраивать неантизированные переменные в ваши запросы, так как вы оставляете себя широко открытым для Атака SQL-инъекции . Вот пересмотренная версия, но имейте в виду, что я немного заржавел с mysqli и не могу проверить это без вашей БД:
$query = "
SELECT
photos.photo_id, members.member_name, photos.photo_title, photos.photo_film,
photos.photo_height, photos.photo_width
FROM members, photos
WHERE members.member_id = photos.member_id
";
$types = "";
$params = array();
if ($form_photo_title !="") {
$query.= "AND photos.photo_title = ? ";
$types .= "s";
$params[] = $form_photo_title;
}
if ($form_member_name !=0) {
$query .= "AND members.member_name = ? ";
$types .= "s";
$params[] = $form_member_name;
}
if ($form_type !="") {
$query .= "AND photo.photo_film = ? ";
$types .= "s";
$params[] = $form_type;
}
if (!($statement = mysqli_prepare($link, $query)))
throw new Exception(mysqli_error($link));
// this tells the statement to substitute those question marks with each of
// the values in the $params array. this is done positionally, so the first
// question mark corresponds to the first element of the array, and so on.
// the $types array is just a string with an indication of the type of the
// value stored at each position in the array. if all three of the above
// clauses are applied, then $types will equal "sss", indicating that the
// first, second and third elements in $params are string types.
// worse still, because the parameters to the query are dynamic, we can't
// call mysqli_stmt_bind_param directly as it does not allow an array to be
// passed, so we have to call it dynamically using call_user_func_array!
// i really hate this about mysqli.
// if all three of your above query clauses are applied, this call translates to
// mysqli_stmt_bind_param(
// $stmt, $types,
// $form_photo_title, $form_member_name, $form_type
// );
array_unshift($values, $stmt, $types);
call_user_func_array("mysqli_stmt_bind_param", $values);
mysqli_stmt_execute($stmt);
// this instructs mysqli to assign each field in your query to each of
// these variables for each row that is returned by mysqli_stmt_fetch().
// this is also positional - if you change the order or number of fields
// in your query, you will need to update this.
mysqli_stmt_bind_result($photo_id, $member_name, $photo_title, $photo_film, $photo_height, $photo_width);
while (mysqli_stmt_fetch($stmt)) {
// $photo_id will be reassigned to the value from the row on each
// loop iteration
echo $photo_id."<br />";
}
Я забыл, что за ужасный зверь, расширение mysqli - если у вас есть доступ к расширению PDO , я
не могу больше рекомендовать вам научиться обходить его и использовать вместо этого.