Tuşa basıp insert ettiğim veri jquery ile gelmiyor bir önceki veri geliyor.

<?php
ob_start();
error_reporting(E_ALL ^ E_NOTICE);
include("baglan.php");


$veri1 = $_POST["veri1"];
$veri2 = $_POST["veri2"];

if (!$veri1) {
echo '<span style="color:red;">veri 1 boş</span>'; exit;
}

if (!$veri2) {
echo '<span style="color:red;">veri 2 boş</span>'; exit;
}

$test = $bag->exec("INSERT INTO testtable (veri1,veri2) VALUES ('".$veri1."','".$veri2."')");
$son = $bag->lastInsertId("testtable");

if ($test) {
$agc = $bag->query("select id,veri1,veri2 from testtable where id='".$son."'")->fetch(); 
echo '<script>var tablo = [';
$al = $bag->query("select id,veri1,veri2 from testtable order by id desc"); 

foreach($al as $ver) {
echo "{ID:'".$ver["id"]."',veri1:'".$ver["veri1"]."',veri2:'".$ver["veri2"]."'},";
	}

echo "{ID:'".$agc["id"]."',veri1:'test',veri2:'test'}];</script>";

} else {
echo '<span style="color:red;">başarısız!</span>'; exit;
}
$bag=null;
ob_end_flush();
?>
echo verilen alanlar diğer sayfada çağrılan kısım.
insert ile 60. Id gönderiliyor fakat ekrana 59 geliyor. Last Insert ID + 1 desem bile vermiyor.
https://github.com/BorisMoore/jquery-tmpl/
http://www.sanwebe.com/assets/ajax-i...d-progressbar/