title: Post checked checkbox values that ate generated dynamically to php using jquery
body: <p>I do have a table that is generated dynamically from MySQL table values. Each listed record has a checkbox.</p>
  
  <p>list.php</p>
  
  <pre><code>$query="SELECT * FROM drivers ORDER BY name";
  $query=$mysqli-&gt;query($query);
  $queryN=mysqli_num_rows($query);
  if($queryN!=0){
     while($row=mysqli_fetch_assoc($query)){
         $id=$row['id'];
         $name=$row['name'];
  
         $output .='&lt;tr id="'.$id.'"&gt;
                    &lt;td&gt;'.$name.'&lt;/td&gt;
                    &lt;td&gt;&lt;input type="checkbox" name="assign" class="assigned" value='.$id.'"/&gt;&lt;/td&gt;
                    &lt;/tr&gt;';
    }
  }else{
         $output .='&lt;tr&gt;
                    &lt;td colspan="2"&gt;No data found&lt;/td&gt;
                    &lt;/tr&gt;';
  }
  </code></pre>
  
  <p>The HTML file</p>
  
  <pre><code>&lt;input type="button" name="send" id="send" value="Send" /&gt;
  </code></pre>
  
  <p>Now the JQuery script that will send only the values of the checked checkboxes in the table:</p>
  
  <pre><code>&lt;script&gt;
  
  $(document).ready(function(){
      $('.send').click(function(){
  
          var checkValues = $('input[name=assign]:checked').map(function()
          {
              return $(this).val();
          }).get();
  
          $.ajax({
              url: 'assigndriver.php',
              type: 'post',
              data: { ids: checkValues },
              success:function(data){
  
              }
          });
      });
  });
  
  &lt;/script&gt;
  </code></pre>
  
  <p>Finally, the PHP file assigndriver.php that will insert the array with the values of only checked checkboxes:</p>
  
  <pre><code>   include "../connect_to_mysql.php";
  
     $id = array();
  
     if(isset($_POST['ids'])){
  
      $id  = $_POST['ids'];
          for ($i = 0; $i &lt; count($id); $i++) {
               $id_new = $id[$i];
               $sql="INSERT INTO teste (campo) VALUES ('$id_new')";    
          }     
      }
  </code></pre>
  
  <p>Well, I would like to know why it isn't working and if in this way the correct value of the checkbox, that must be the variable $id is being posted correctly to the PHP file.</p>
  
  <p>Thank you</p>