Hi All,

This one has me stumped.

I have the following code which is working just fine:

Code:
$options = array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC);
$db = new PDO("mysql:host={$host};dbname={$dbname};charset=utf8", $username, $password, $options);
Code:
//BUILD SQL QUERY FOR DISTRIBUTORS OVERVIEW
$stmt = $db->prepare("SELECT distributors.ID, distributors.Distributor, distributors.Region, distributors.CM, users.First_Name, users.Last_Name FROM distributors INNER JOIN users ON distributors.CM=users.ID LIMIT :page, 18");
$stmt->bindValue(':page', $page, PDO::PARAM_STR);
$stmt->execute(); 
$rows = $stmt->fetchAll();
I would like to insert another parameter:

Code:
if ($s == 'search'){$search_query_terms = "WHERE $filter LIKE '%$terms%'";} else {$search_query_terms = null;};
Code:
$stmt = $db->prepare("SELECT distributors.ID, distributors.Distributor, distributors.Region, distributors.CM, users.First_Name, users.Last_Name FROM distributors INNER JOIN users ON distributors.CM=users.ID :search_query_terms LIMIT :page, 18");
$stmt->bindValue(':page', $page, PDO::PARAM_STR);
$stmt->bindValue(':search_query_terms', $search_query_terms, PDO::PARAM_STR);
$stmt->execute(); 
$rows = $stmt->fetchAll();
But this returns an error:

PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 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 '? LIMIT ?, 18' at line 1' in

Any ideas? It works fine if I insert the variable directly into the query.