Get the insert ID or autoincrement value of the previously executes mysql query.
$sql_insert = "insert into sites values (NULL,'')";
$result = mysql_query ($sql_insert);
$siteid = mysql_insert_id();