<?php 
include '../koneksi.php';
$tsub       = $_POST['tsub'];
$tnama      = $_POST['tnama'];

$sql2 = mysqli_query($koneksi, "SELECT count(kd) AS tkd1 FROM n_kode_3 WHERE kd1='$tsub'");
                list($tkd1) = mysqli_fetch_array($sql2);
$kd_ke=$tkd1+1 ;
$tkd=$tsub.$kd_ke ;
$noperk=$tkd.'00' ;

    $query = mysqli_query($mysqli, "INSERT INTO n_kode_3 (kd1,kd2,kd,nama) 
                                    VALUES('$tsub','$kd_ke','$tkd','$tnama')")
                                    or die('Ada kesalahan pada query insert : '.mysqli_error($mysqli));
                                    
    $query = mysqli_query($mysqli, "INSERT INTO nawal (noperk,perk,klp,nosub) 
                                    VALUES('$noperk','$tnama','$tsub','$tkd')")
                                    or die('Ada kesalahan pada query insert : '.mysqli_error($mysqli));

//mysqli_query($koneksi, "insert into user values (NULL,'$nama','$xusername','$xpassword','$xlevel','$xkdr','$foto','$yt','$xkar')");
header("location:kode_akunt.php?kd2=11&kd3=1");