title: Updating multiple rows in mysql database with serialized form data
body: <p>I am trying to update multiple rows in my database with data coming from an html form data via AJAX. I don't have any problem with updating the database but I used several queries to update each row. What is the PROPER way to update multiple rows coming from a big form using AJAX? A foreach loop?</p>
  
  <pre><code>if ( isset($_POST['updateData']) ) {
      parse_str($_POST['fields']);
  
      $update1 = $db-&gt;execute("UPDATE content SET content_text=? WHERE page_id = '".$page_id."' AND lang_code = '".$lang_code."' AND content_id =1", array($field1));
      $update2 = $db-&gt;execute("UPDATE content SET title=?, content_text=? WHERE page_id = '".$page_id."' AND lang_code = '".$lang_code."' AND content_id =2", array($field2_title, $field2));
      $update3 = $db-&gt;execute("UPDATE content SET title=? WHERE page_id = '".$page_id."' AND lang_code = '".$lang_code."' AND content_id =3", array($field3_title));
  
  }
  </code></pre>
  
  <p>My database</p>
  
  <pre><code>ID | content_id | page_id | lang_code | title      | content_text |
  ---------------------------------------------------------------------
  1  | 1          | 2       | en        |            | text1        |
  2  | 2          | 2       | en        | title2     | text2        |
  3  | 3          | 2       | en        | title3     |              |
  </code></pre>
  
  <p>My form looks like that :</p>
  
  <pre><code>&lt;input name="field1"&gt;
  &lt;input name="field2_title"&gt;
  &lt;input name="field2"&gt;
  &lt;input name="field3_title"&gt;
  </code></pre>
  
  <p>My script:</p>
  
  <pre><code>var form_data = $(this).serialize();
  $.ajax({
      type : 'POST',
      url  : '#',
      data : {
          updateData : 1,
          fields : form_data
      }
  });
  </code></pre>