title: Post form and update multiple rows with mysql
body: <p>I have searched all over this website, but not yet found the answer for this. Pr maybe I am not able to apply it correctly. I have a form that grabs all photos with a certain GALLERY_id attached to it. The backend user can then change the title of the photo and change the tags. After submitting the form the query should update all rows. Here is what I have so far which does not doe anyting:</p>
  
  <p><strong>THE FORM</strong></p>
  
  <pre><code>if(isset($_GET['id']))
  {
  
      $id=$_GET['id'];
      $result = $db-&gt;prepare("SELECT * FROM photos WHERE gallery_id = :gallery_id ");      
      $result-&gt;bindParam(':gallery_id', $id);
      $result-&gt;execute();
  
      echo '&lt;form action="" method="POST"&gt;';
      echo "&lt;ul id='photos'&gt;";
  
      for ($i = 0; $row = $result-&gt;fetch(); $i++)
      {
  
          $id = $row['id'];
          $title = $row['title'];
          $tags = $row['tags'];
          $src = $row['src'];
  
          echo "&lt;li&gt;&lt;a class='lightbox' href='images/$src'&gt;&lt;img src='images/$src' id='$id' alt='$title' /&gt;&lt;/a&gt;&lt;br /&gt;";
          echo "&lt;input type='text' name='photo_title' value='$title' /&gt;&lt;br /&gt;";
          echo "&lt;input type='text' name='photo_tags' value='$tags' /&gt;";
          echo "&lt;input type='hidden' name='photo_id' value='$id' /&gt;";
          echo "&lt;/li&gt;";
      }
  
      echo "&lt;/ul&gt;";
  
  }
  
  ?&gt;
  &lt;div style="clear:both"&gt;&lt;/div&gt;
  &lt;input type="submit" name="changeTitle" value="Save"/&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p><strong>UPDATE QUERY</strong></p>
  
  <pre><code>if (isset($_POST['changeTitle']))
  {
      foreach ($_POST as $p)
      {
          $id=$p['photo_id'];
          $title=$p['photo_title'];
          $tags=$p['photo_tags'];
  
  
          $sql = "UPDATE photos SET title=?, tags=? WHERE id=?";
          $query = $db-&gt;prepare($sql);
          $query-&gt;execute(array($title, $tags, $id));
  
      }
  }
  </code></pre>