title: Warning: PDOStatement::execute() [pdostatement.execute]: SQLSTATE[HY093]: Invalid parameter number:
body: <p>I am attempting to use the following code to search a database using words in a search field.</p>
  
  <p>For some reason I am getting the following error</p>
  
  <blockquote>
    <p>Warning: PDOStatement::bindValue() [pdostatement.bindvalue]:
    SQLSTATE[HY093]: Invalid parameter number: Columns/Parameters are
    1-based in..</p>
  </blockquote>
  
  <p>Here is the function code:</p>
  
  <pre><code>// Retrieve search results
      function retrieve_search_posts($searchfield){
          //test the connection
          try{
              //connect to the database
              $dbh = new PDO("mysql:host=localhost;dbname=mjbox","root", "usbw");
          //if there is an error catch it here
          } catch( PDOException $e ) {
              //display the error
              echo $e-&gt;getMessage();
  
          }
  
          $where = array();
  
          $words = preg_split('/[\s]+/',$searchfield);
  
          $total_words = count($searchfield);
  
          for($i = 0; $i &lt; count($words); $i++){
  
              $where[] .= "`post_title` LIKE ?";
  
          }
  
          $where_string = implode(" OR ", $where);
  
          $query = "
                                  SELECT  p.post_id, post_year, post_desc, post_title, post_date, img_file_name, p.cat_id
                                  FROM    mjbox_posts p
                                  JOIN    mjbox_images i
                                  ON      i.post_id = p.post_id
                                          AND i.cat_id = p.cat_id
                                          AND i.img_is_thumb = 1
                                          AND post_active = 1
                                  WHERE post_title LIKE ?
                                  ORDER BY post_date
                                  DESC";
  
          $stmt = $dbh-&gt;prepare($query);
  
          foreach($words AS $index =&gt; $word){
              $stmt-&gt;bindValue($index, $word, PDO::PARAM_STR);
          }
  
          $stmt-&gt;execute();
  
          $searcharray = $stmt-&gt;fetchAll(PDO::FETCH_ASSOC);
  
          return $searcharray;
      }
  </code></pre>
  
  <p>What have I done wrong to cause the outputted error message?</p>