title: PDO update only updating one row
body: <p>So I am quite confused by this problem. I am sending a post to this <code>PHP</code> file using <code>AJAX</code> and it takes my array, reverses it, chunks it and then uses it to bind values. Each chunk holds a row worth of info to update, so each iteration of the for loop updates a row. </p>
  
  <p>The first time I attempted this I used the following code.    </p>
  
  <pre><code>if(isset($_POST['saveEdits'])) {
      $i = 0;
      $j = 1; 
      $update = array();          
      $update = $_POST['saveEdits'];
      $chunk_count = count($update)/7;    
      $backwards = array_reverse($update);
      $chunks = array_chunk($backwards, 7);               
  
      try {
          for($i; $i &lt; $chunk_count; $i++ ) {
              $update_project = $db-&gt;prepare('
                  UPDATE projects
                  SET comments = ?,
                      contact = ?,
                      est_end = ?,
                      est_start = ?,  
                      apm = ?,  
                      pm = ?                              
                  WHERE id = ?
              ');
  
              foreach ($chunks[$i] as $field =&gt; $val) {                           
                  $update_project-&gt;bindValue($j++, $val, PDO::PARAM_STR);                                 
              }           
              $update_project-&gt;execute();
  
          }
  
          echo 'Projects Updated';        
  
      } catch(PDOException $e) {
          die($e-&gt;getMessage());
      }   
  } else {    
      echo 'could not update projects table';
  }
  </code></pre>
  
  <p>and I would get the following error each time</p>
  
  <pre><code>Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in C:\xampp\htdocs\core\functions\update_projects.php on line 31
  </code></pre>
  
  <p>so it was suggested that I change</p>
  
  <pre><code>$i = 0;
  </code></pre>
  
  <p>to </p>
  
  <pre><code>$i = 1;
  </code></pre>
  
  <p>This somehow works. This lets me insert the data one time, but does not insert all of the data. The fact that this works <em>at all</em> is baffling to me. $i is the holder for my loop index, and chunks index. It needs to go from 0 - whatever. I don't understand how starting at 1 helps in any way. $j is the holder for the param binder, which <em>should</em> start at 1. </p>
  
  <p>Some additional info. If I var_dump(chunks[0]) and var_dump(chunks[1]) I see the following</p>
  
  <pre><code>array(7) { [0]=&gt; string(13) "more comments" [1]=&gt; string(9) "jimmy doe" [2]=&gt; string(6) "1-1-14" [3]=&gt; string(7) "12-1-13" [4]=&gt; string(9) "janey doe" [5]=&gt; string(9) "jonny doe" [6]=&gt; string(2) "17" } 
  array(7) { [0]=&gt; string(13) "some comments" [1]=&gt; string(7) "jim doe" [2]=&gt; string(6) "1-1-14" [3]=&gt; string(7) "12-1-13" [4]=&gt; string(8) "jane doe" [5]=&gt; string(7) "jon doe" [6]=&gt; string(2) "16" }
  </code></pre>
  
  <p>So review. <code>$i = 0</code> and I get the error up top, <code>$i = 1</code> I get to insert one row and it's over. Can someone please tell me what's going on here? Any help is appreciated</p>