php - Mysqli LIKE statement not working -


i'm getting these weird errors, , i've been , down code, commenting , rewriting, , googling things. perhaps guys see i'm not seeing:

$mysqli = new mysqli('host','login','passwd','db'); if($mysqli->connect_errno > 0){ die('cannot connect: '. $mysqli->connect_error); } // see if there 1 term or multiple terms if (count($search) == 1) { // if 1 term, search $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                      gsa_committees,             gsa_committee_reports,             gsa_funds,             gsa_meeting_minutes,             gsa_officers,             gsa_representatives                      (gsa_committees.committee $like) ,                                 gsa_committees.committee not null"; } if(!$result = $mysqli->query($stmt)){ die('bad query: '. $mysqli->error); } 

this gives me error message:

bad query: have error in sql syntax; check manual corresponds mysql server version right syntax use near '%archac%) , gsa_committees.committee not null' @ line 34 

which know isn't true. if change las part this:

where gsa_committees.committee $like"; 

i error message:

bad query: have error in sql syntax; check manual corresponds mysql server version right syntax use near '%archac%' @ line 34 

everywhere i've looked, string "%".search."%" seems correct method, server doesn't seem here.

interesting side note: have different statement working on page on same server, won't work reason.

thanks!

try putting single quotes around search term ($like variable).

for example: (gsa_committees.committee '$like')


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -