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

<?php 
error_reporting(0);

$actget = $_GET['actget'];
$act = $_POST['act'];
$id = $_POST["id"];
$nahkoda = $_POST['nama'];
$alamat = $_POST['alamat'];
$telp = $_POST['telepon'];

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

	$sql="INSERT INTO tb_nahkoda(Nahkoda,Alamat,No_Telp,Status) VALUES('$nahkoda','$alamat','$telp','1')";
	if (!mysql_query($sql,$test)){
  	die('Error: ' . mysql_error());
	}
?>
<script>window.location = "<?php echo $base?>data-nahkoda"</script>
<?php	

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

	$sql="update tb_nahkoda set Nahkoda = '".$nahkoda."', Alamat = '".$alamat."', No_Telp = '".$telp."' where Id_Nahkoda = '".$id."'";
	if (!mysql_query($sql,$test)){
  	die('Error: ' . mysql_error());
	}
?>
<script>window.location = "<?php echo $base?>data-nahkoda"</script>
<?php

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

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

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

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