<?php
include "../koneksi.php";

$stpj_id = $_POST['mystpjId'];
$plan_id = $_POST['myplanId'];
$qty = $_POST['myqty'];
$kode = $_POST['mykode'];
$lot = $_POST['mylot'];
$nick = $_POST['mynick'];

$hitung = count($plan_id);

for( $i=0; $i < $hitung; $i++ ) {
	if($plan_id[$i]!==''&&$kode[$i]!==''&&$lot[$i]!=='') {
		if($stpj_id[$i]!=='') {
			$query = "UPDATE stpj SET Kode = '$kode[$i]',
									NoLot = '$lot[$i]',
									Nick = '$nick[$i]'
									WHERE STPJ_ID = '$stpj_id[$i]'";
	
				mysqli_query($koneksi, $query)
				or die ("Gagal Perintah SQL".mysql_error());
	} else {
    $query = "insert INTO stpj SET
									PlanID = '$plan_id[$i]',
									Kode = '$kode[$i]',
									NoLot = '$lot[$i]',
									Nick = '$nick[$i]'
										";

	mysqli_query($koneksi, $query)
	or die ("Gagal Perintah SQL".mysql_error());
	}
} else {
	$query = "DELETE FROM stpj 
	WHERE STPJ_ID = '$stpj_id[$i]'";

	mysqli_query($koneksi, $query)
	or die ("Gagal Perintah SQL".mysql_error());
}
}

header('Location:stpj.php?id='.$plan_id[0].'&qty='.$qty[0]);

?>

