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

<?php 
error_reporting(0);

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

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

	$sql="insert into tb_abk (nama, alamat, telp, status) VALUES('$nama','$alamat','$telp','1')";
	if (!mysql_query($sql,$test)){
  	die('Error: ' . mysql_error());
	}
?>
<script>window.location = "<?php echo $base?>data-abk"</script>
<?php	

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

	$sql="update tb_abk set nama = '".$nama."', alamat = '".$alamat."', telp = '".$telp."' where id_abk = '".$id."'";
	if (!mysql_query($sql,$test)){
  	die('Error: ' . mysql_error());
	}
?>
<script>window.location = "<?php echo $base?>data-abk"</script>
<?php

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

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

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

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