title: PHP prepared statement array update
body: <p>This is a follow-up question to another post (<a href="https://stackoverflow.com/questions/17554094/php-insert-into-mysql-from-array">link</a>)</p>
  
  <p>I'm trying to wrap my head around how I perform a mysql update using a prepared statement.  I need to add the WHERE id = ?.. I'm confused as to how I'm getting that back from my array.  Thanks!</p>
  
  <p><strong>My form:</strong></p>
  
  <pre><code>&lt;form action="update.php" method="post"&gt;
  
    &lt;input type="hidden" name="id" value=""/&gt;
    &lt;input type="text" name="name" value=""/&gt;
    &lt;input type="text" name="age" value=""/&gt;
  
    &lt;input type="hidden" name="id" value=""/&gt;
    &lt;input type="text" name="name" value=""/&gt;
    &lt;input type="text" name="age" value=""/&gt;
  
    &lt;input type="submit" value="submit" name="submit" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p><strong>PHP:</strong></p>
  
  <pre><code>// Create statement object
  $stmt = $db-&gt;stmt_init();
  
  
  if (isset($_POST['submit'])) {
  
  // Create a prepared statement
  if($stmt-&gt;prepare("UPDATE contact SET (name, age) VALUES (?, ?)")) {
  
      // Bind your variables to replace the ?s
      $stmt-&gt;bind_param('si', $name, $age);
  
  
      $returnedData = $_POST['data'];
  
  for($i=0;$i&lt;count($returnedData);$i+=3){
      $id = $returnedData[$i]['id']
      $name = $returnedData[$i+1]['name'];
      $age = $returnedData[$i+2]['age'];
      $stmt-&gt;execute();
  }
  
  
      // Close statement object
      $stmt-&gt;close();
  }
  </code></pre>
  
  <p>}</p>