Я получаю эти странные ошибки, и я был вверх и вниз по коду, комментируя и переписывая, и отправлял все игры. Возможно, вы, ребята, будете видеть, что я не вижу:Заявление Mysqli LIKE не работает
$mysqli = new mysqli('host','login','passwd','db');
if($mysqli->connect_errno > 0){ die('Cannot connect: '. $mysqli->connect_error); }
// See if there is one term or multiple terms
if (count($search) == 1) {
// If one term, search for that
$like = $search[0];
$stmt = "SELECT
gsa_committees.id,
gsa_committees.committee,
gsa_committees.appointer,
gsa_committees.representatives,
gsa_committees.contact,
gsa_committees.category,
gsa_committees.attachments,
gsa_committees.labels,
gsa_committee_reports.committee,
gsa_committee_reports.title,
gsa_committee_reports.author,
gsa_committee_reports.link,
gsa_funds.id,
gsa_funds.fund,
gsa_funds.attachments,
gsa_funds.labels,
gsa_meeting_minutes.title,
gsa_meeting_minutes.link,
gsa_officers.office,
gsa_officers.dept,
gsa_officers.name,
gsa_representatives.program_dept,
gsa_representatives.representatives,
gsa_representatives.alternate
FROM
gsa_committees,
gsa_committee_reports,
gsa_funds,
gsa_meeting_minutes,
gsa_officers,
gsa_representatives
WHERE
(gsa_committees.committee LIKE $like) AND
gsa_committees.committee IS NOT NULL";
}
if(!$result = $mysqli->query($stmt)){ die('Bad query: '. $mysqli->error); }
Это дает мне сообщение об ошибке:
Bad query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%ARCHAC%) AND gsa_committees.committee IS NOT NULL' at line 34
Что я знаю, это не так. Если я изменю что-лас части только это:
WHERE gsa_committees.committee LIKE $like";
Я получаю сообщение об ошибке:
Bad query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%ARCHAC%' at line 34
Везде я смотрел, строка "%".search."%"
, кажется, правильный метод, но мой сервер Безразлично Кажется, это нравится здесь.
Интересное примечание стороны: У меня другое заявление LIKE, работающее на другой странице на том же сервере, это просто не будет работать по какой-то причине.
Спасибо!
Каково значение переменной $ like, которую вы получаете? – Maximus2012
Возможно, есть {и} вокруг '$ like'? – Markasoftware
^^ и правильно ли он указан –