title: Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens
body: <p>After reading all others questions about the HY093 i cant figure out what is causing the error </p>
  
  <p>I am uploading a csv file and inserting its values to mysql using PDO.</p>
  
  <p>Here is what i get:</p>
  
  <blockquote>
    <p>Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens </p>
  </blockquote>
  
  <p>Here is the code that i am using:</p>
  
  <pre><code>&lt;?php
  
  if (in_array($extension, $allowed_extensions)) {
  
  if (!empty($_FILES['file'])) {
  
      if ($_FILES['file']['error'] == 0) {
  
          // check extension
          $file = explode(".", $_FILES['file']['name']);
          $extension = array_pop($file);
  
          if (in_array($extension, $allowed_extensions)) {
  
              if (move_uploaded_file($_FILES['file']['tmp_name'], $upload_path . '/' . $_FILES['file']['name'])) {
                  if (($handle = fopen($upload_path . '/' . $_FILES['file']['name'], "r")) !== false) {
  
                      $keys = array();
                      $out = array();
  
                      $insert = array();
  
                      $line = 1;
  
                      while (($row = fgetcsv($handle, 0, ',', '"')) !== FALSE) {
  
                          foreach ($row as $key =&gt; $value) {
                              if ($line === 1) {
                                  $keys[$key] = $value;
                              } else {
                                  $out[$line][$key] = $value;
                              }
                          }
  
                          $line++;
                      }
  
                      fclose($handle);
  
                      if (!empty($keys) &amp;&amp; !empty($out)) {
  
                          $db = new PDO('mysql:host=localhost;dbname=pitstop', 'root', '');
                          $db-&gt;exec("SET CHARACTER SET utf8");
  
                          foreach ($out as $key =&gt; $value) {
                              $sql = "INSERT INTO `csat_dump` (`";
                              $sql .= implode("`, `", $keys);
                              $sql .= "`) VALUES (";
                              $sql .= implode(", ", array_fill(0, count($keys), "?"));
                              $sql .= ")";
                              $statement = $db-&gt;prepare($sql);
                              if ($value === null) {
                                  $value = 'null';
                              }
                              $statement-&gt;execute($value);
                          }
  
                          $message = '&lt;span class="green"&gt;File has been uploaded successfully&lt;/span&gt;';
                      }
                  }
              }
          } else {
              $message = '&lt;span class="red"&gt;Only .csv file format is allowed&lt;/span&gt;';
          }
      } else {
          $message = '&lt;span class="red"&gt;There was a problem with your file&lt;/span&gt;';
      }
  }
  </code></pre>
  
  <p>here is how my keys array looks like </p>
  
  <pre><code>Array ( 
      [0] =&gt; SBT Interview End Date 
      [1] =&gt; Week End Date 
      [2] =&gt; YYYY Mm 
      [3] =&gt; SBT Case ID 
      [4] =&gt; SBT Response ID 
      [5] =&gt; SBT Agent 
      [6] =&gt; SBT Channel Name 
      [7] =&gt; SBT Msg Created 
      [8] =&gt; SBT Close Date 
      [9] =&gt; SBT Contact Count 
      [10] =&gt; SBT Queue Nm 
      [11] =&gt; SBT Vendor Name
      [12] =&gt; SBT Location Name 
      [13] =&gt; SBT Message Age 
      [14] =&gt; SBT Q1 (Email overall score) 
      [15] =&gt; SBT Q2 (Was your issue resovled?) 
      [16] =&gt; SBT Q201(NPS) 
      [17] =&gt; SBT Q200(Ease of contact Customer Care) 
      [18] =&gt; SBT Q186 (Verbatim) 
      [19] =&gt; FCR 
      [20] =&gt; FCR Count 
  ) 
  </code></pre>
  
  <p>and here is my values aray:</p>
  
  <pre><code>Array ( 
      [0] =&gt; 2014-06-29 
      [1] =&gt; 2014-07-05 
      [2] =&gt; 2014-06 
      [3] =&gt; 140625-057952 
      [4] =&gt; 1151071 
      [5] =&gt; agentname 
      [6] =&gt; Email 
      [7] =&gt; 2014-06-25 
      [8] =&gt; 2014-06-29 
      [9] =&gt; 0 
      [10] =&gt; AMR-EN-tech 
      [11] =&gt; tech- Agents 
      [12] =&gt; SMB - Agents 
      [13] =&gt; 4720 
      [14] =&gt; 8 
      [15] =&gt; 1 
      [16] =&gt; 8 
      [17] =&gt; 10 
      [18] =&gt; 
      [19] =&gt; 1 
      [20] =&gt; 1 
  ) 
  </code></pre>
  
  <p>any help</p>
  
  <p>Sample CSV data:</p>
  
  <pre><code>SBT Interview End Date,Week End Date,YYYY Mm,SBT Case ID,SBT Response ID,SBT Agent,SBT Channel Name,SBT Msg Created,SBT Close Date,SBT Contact Count,SBT Queue Nm,SBT Vendor Name,SBT Location Name,SBT Message Age,SBT Q1 (Email overall score),SBT Q2 (Was your issue resovled?),SBT Q201(NPS),SBT Q200(Ease of contact Customer Care),SBT Q186 (Verbatim),FCR,FCR Count
  6/29/2014,7/5/2014,2014-06,140625-057952,1151071,agent1,Email,6/25/2014,6/29/2014,0,AMR-EN-xxxxxx-T1,SMB - Agents,SMB - Agents,4720,8,1,8,10,some text1,1,1
  6/29/2014,7/5/2014,2014-06,140625-064834,1151074,agent2,Email,6/25/2014,6/29/2014,0,AMR-EN-xxxxxx-T2,SMB - Agents,SMB - Agents,4587,9,1,9,9,some text2,1,1
  6/29/2014,7/5/2014,2014-06,140625-054127,1151083,agent3,Email,6/25/2014,6/29/2014,0,AMR-EN-xxxxxx-T3,SMB - Agents,SMB - Agents,4799,8,1,10,3,some text3,1,1 
  </code></pre>