I have a radio button-form which sends post requests with ajax. Post data should be inserted into two different tables.
My problem is that my $ID variable always work with table1, but only say 3 out of 10 attempts on table2. 
Ajax code:
post_radio();
function post_radio() {
  $('.ok').change(function() {
    var current_element = $(this);
    var id = $(this).attr('id');
    var result = $("input[name='result']:checked").val();
    var table_id = "<?php echo $table_id?>";
    $.post('posta.php', {
      "ID": id,
      "result": result,
      "table_ID": table_id
    }, function(data) {
      $('.total_status').html(data);
    });
  });
}
Post PHP script:
$result = $_POST['result'];
$ID = $_POST['ID'];
$table_ID= $_POST['table_ID'];
$sql="UPDATE table1 
      SET result='$result', touched='yes' timestamp=now() 
      WHERE ID='$ID'";
mysql_query($sql, $dbconnection);
$sql2="SELECT * 
       FROM table1 
       WHERE table_ID='$table_ID' 
       AND touched='yes'";
$result2 = mysql_query($sql2, $dbconnection);
$rows = mysql_num_rows($result2);
$complete = ROUND(($rows/189)*100,0);
$sql3="UPDATE table2 
       SET complete='$complete', last_ID='$ID' 
       WHERE table_ID='$table_ID'";
mysql_query($sql3, $dbconnection);
$sql works every time
$sql2 works every time ($complete correctly calculated)
$sql3 works every time (complete column is correctly filled with $complete)
Problem is that column "last_ID" should be filled with $ID, but this seem to only work randomly
 
    