title: JQuery Datatables serialized data into mysql database
body: <p>I'm really new at javascript and JQuery and I'm using JQuery datatables. I have read the page for 100 times and compared the html source and I managed to figure out how to pass the only checked fields into the sData array... Anyway...</p>
  
  <p>I have this array:</p>
  
  <pre><code>var sData
  </code></pre>
  
  <p>which alerts me which rows I have selected when I submit the form, it gives something like this:</p>
  
  <pre><code>1=1&amp;2=2&amp;10=10&amp;18=18
  </code></pre>
  
  <hr>
  
  <p>Before this I used simple table with each row a button which reserved me the one I choose, so this step is really confusing for me...</p>
  
  <p>I used this query to add them to the database:</p>
  
  <pre><code>if (isset($_POST['addtolist']) ) 
  {
      $itemid=mysql_real_escape_string($_POST['itemid']);
      $AddToListQuery = "
                      INSERT INTO
                      reservelist
                     (itemid, projectid)
                      VALUES
                     ('$itemid', '" . mysql_real_escape_string($_SESSION['projectidtoreserve']) . "')
                     ";      
      mysql_query($AddToListQuery, $conn);
      header('Location: pm_reserving.php');
      exit();
  }
  </code></pre>
  
  <p>And it executed every time after clicking on a button at the specified table row.</p>
  
  <p>But now I have no clue how to pass this sData array to the query...</p>
  
  <p>I can't just use this <code>sData</code> like it now is to enter it into the database, because it wouldn't make any sense :/... What do I have to do with this sData?</p>
  
  <p><strong>EDIT</strong><br />
  My JQuery code now:</p>
  
  <pre><code>        $('#form').submit( function() {
              var sData = $('input', oTable.fnGetNodes()).serialize();
              alert( "The following data would have been submitted to the server: \n\n"+sData );
  
          } );
  
          oTable = $('#table1').dataTable();
  </code></pre>
  
  <p>My form:</p>
  
  <pre><code>&lt;form id="form" action="" method="post"&gt;
  &lt;button type=submit name=addtolist&gt;Button&lt;/button&gt;
  </code></pre>
  
  <p>When I submit the form, I receive the alert mentioned above (but now with id1=1&amp;id2=2 etc.).</p>
  
  <p>PHP:</p>
  
  <pre><code>if (isset($_POST['addtolist']) ) 
  {
      $x=1;
      $values=array('+sData');
      while(isset($_POST['id'.$x]))
      {
          $values[$x-1]=$_POST['id'.$x];
          $AddToListQuery = "
                          INSERT INTO
                          reservelist
                         (itemid, projectid)
                          VALUES
                         ('". mysql_real_escape_string($_POST['id'.$x]) ."', '" . mysql_real_escape_string($_SESSION['projectidtoreserve']) . "')
                         ";
          $x++;
      }
      mysql_query($AddToListQuery, $conn);
      header('Location: pm_reserving.php');
      exit();
  }
  </code></pre>
  
  <p>This PHP loop is probably a big fail...But I need this sData var to put into the PHP variable... Oh god I'm so lame at this.</p>