title: Number of bound variables does not match number of tokens error when building dynamic query
body: <p>I keep getting the following error: </p>
  
  <blockquote>
    <p>Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter
    number: number of boundvariables does not match number of tokens</p>
  </blockquote>
  
  <p>when trying to build a dynamic SQL query. Any idea where the damage is being done? I've searched for hours and still no luck  </p>
  
  <pre><code>$park = $_POST["park"];
  $lecturestyle_id = $_POST["lecturestyle"];
  $group_size = $_POST["groupsize"];
  $roomstructure_id = $_POST["roomstructure"];
  $array = explode(",", $_POST["facilities"]);
  
  // change Mon here
  
  echo '&lt;td class="gridSide"&gt;
  Mon
  ';
  
  // build facilities search
  
  for($i = 0; $i &lt; count($array); $i++){  
      if ($array[$i]!=0) {
      $fac .= ' AND facilities_id='.$array[$i].'';
      }
      else
      $fac .= '';
  }
  
  echo '&lt;/td&gt;';
  
  
  for ($i = 1; $i &lt;= 9; $i++) 
  {
  
          // change mon here
  
          echo '&lt;td class="box" id="mon'.$i.'"&gt;';
  
          // dynamically build sql query
  
          $sql = 
          "
          SELECT DISTINCT COUNT(*) FROM ts_room rm
          LEFT JOIN ts_roomfacilities rf
          ON rm.id = rf.room_id
          LEFT join ts_facilities f
          ON f.id = rf.facilities_id
          LEFT JOIN ts_building b
          ON rm.building_id=b.id
          WHERE capacity&gt;=:group_size";
  
          $sql .= $fac;
  
          if($park!="Any") {
          $sql .= " AND b.park_id=:park";
          }
  
          if($lecturestyle_id!="Any") {
          $sql .= " AND lecturestyle_id=:lecturestyle_id";
          }
  
          if($roomstructure_id!="Any") {
          $sql .= " AND roomstructure_id=:roomstructure_id";
          }
  
          $sql .= " AND rm.id NOT IN
          (SELECT COUNT(*)
           FROM ts_request rq
           LEFT JOIN ts_allocation a ON a.request_id = rq.id
           WHERE 
           day_id=1 AND period_id=:period
           OR a.status IS NOT NULL
           AND a.status IN ('Pending','Declined','Failed'))";
  
           $stm = $pdo-&gt;prepare( $sql );
           $stm-&gt;execute( array( ':roomstructure_id' =&gt; $roomstructure_id, ':lecturestyle_id' =&gt; $lecturestyle_id, 
           ':group_size' =&gt; $group_size, ':park' =&gt; $park, ':period' =&gt; $i));
           $rows = $stm-&gt;fetchColumn();
  
           echo $rows.'&lt;br&gt;free&lt;/td&gt;';            
           echo '&lt;/td&gt;';
  
  }
  </code></pre>