<?php 
error_reporting(0);
include("config/connection.php");

$actget = $_GET['actget'];
$act = $_POST['act'];
$id = $_POST["id"];
$nama = $_POST['nama'];
$keterangan = $_POST['keterangan'];

//TAMBAH DATA
if ($act == 1){

	$sql="insert into tb_jenis_kapal (Jenis, Keterangan, Status) values ('".$nama."','".$keterangan."','1')";
	if (!mysql_query($sql,$test)){
  	die('Error: ' . mysql_error());
	}
?>
<script>window.location = "<?php echo $base?>data-jenis-kapal"</script>
<?php	

//UBAH DATA
}elseif ($act == 2){

	$sql="update tb_jenis_kapal set Jenis = '".$nama."', Keterangan = '".$keterangan."' where Id = '".$id."'";
	if (!mysql_query($sql,$test)){
  	die('Error: ' . mysql_error());
	}
?>
<script>window.location = "<?php echo $base?>data-jenis-kapal"</script>
<?php

//NONAKTIF DATA
}elseif($act == 3){
	$sql="update tb_jenis_kapal set Status = '0' where Id = '".$id."'";
	if (!mysql_query($sql,$test)){
  	die('Error: ' . mysql_error());
	}
?>
<script>window.location = "<?php echo $base?>data-jenis-kapal"</script>
<?php

//CARI DATA UNTUK EDIT
}elseif ($actget == 1){

	$id = $_GET['id'];
    $sql = "SELECT * from tb_jenis_kapal WHERE Id = '".$id."'"; 
	$hasil = mysql_query($sql) or die("Kesalahan Pada SQL");
	mysql_close($test);

    $query = mysql_fetch_array($hasil);
    echo json_encode($query);
	
}
?>
