I wrote a script that should simply insert the data into the SELECT and return the result:
$searchSql = "SELECT * FROM consult AS c LEFT JOIN user AS u ON c.lectorId=u.id WHERE c.date>=NOW() "; $sqlParams = []; if (!empty($group)){ $searchSql .= "AND WHERE `group` LIKE :group"; $sqlParams[':group'] = "%$group%"; } if (!empty($discipline)){ $searchSql .= "AND WHERE `discipline` LIKE :discipline"; $sqlParams[':discipline'] = "%$discipline%"; } if (!empty($lector)){ $searchSql .= "AND WHERE `lector` LIKE :lector"; $sqlParams[':lector'] = "%$lector%"; } $stm = $db->prepare($searchSql); foreach ($sqlParams as $key=>$value){ $stm->bindValue($key,$value,PDO::PARAM_STR); } $stm->execute(); $result = $stm->fetchAll(); Request that arrives in MySQL:
SELECT * FROM consult AS c LEFT JOIN user AS u ON c.lectorId=u.id WHERE c.date>=NOW() AND WHERE `group` LIKE '%12%' Why was the parameter: group inserted in single quotes?
PHP 5.6 MySQL 5.5 (OpenServer 5.2.4)
AND WHERE). The request threw an error due to incorrect syntax. - atom-22