<?php
	
	
	include "koneksi.php";
	$id=mysqli_real_escape_string($conn,$_GET["id"]);
	
	//select ke data_promosi sesuai id\\\\
	$a = "SELECT * FROM data_demosi WHERE id=".$id;
	$res = mysqli_query($conn, $a);
	//nyimpan hasil query data promosi\\
	$nik;
	$jabatan_baru = '';
	$divisi_baru = '';
	
	while ($row = mysqli_fetch_assoc($res)) 
	{
              $nik = $row["nik"];
			  $jabatan_baru = $row["divisi_baru"];
			  $divisi_baru = $row["jabatan_baru"];
	}
	
    $tanggal_disetujui = date('d / m / yy');
	
	//$query="UPDATE mahasiswa SET nim='$nim',nama='$nama',jurusan='$jurusan',jenis_kelamin='$jenis_kelamin',alamat='$alamat' where id_mahasiswa='$id_mahasiswa'";

	
	$query = "UPDATE data_karyawan 
	      SET jabatan='$divisi_baru', 
		      departement='$jabatan_baru' 
	      WHERE nik=".$nik;
    $result = mysqli_query($conn, $query);	
	
    $q = "UPDATE data_demosi SET status='2',tanggal_disetujui='$tanggal_disetujui' WHERE id=".$id;
	$result2 = mysqli_query($conn, $q);

    echo "nik : " .$nik; 
	echo "jabatan baru : " .$jabatan_baru; 
	echo "divisi baru : " .$divisi_baru; 


	if($result & $result2)
	{
		
		header("location:suratSkUsulanDemosi.php?p=1");
		echo $q;
	}
	else
	{
		//header("location:tambahkaryawan.php?pesan=gagalInput");
		header("location:suratSkUsulanDemosi.php?p=3");
	echo $query;
	}
	//echo "namanya : " . $nama;
	
	//$q="INSERT INTO kriteria (nama,id_kategori) VALUES ('$nama','$id')";
	//mysqli_query($conn,$q);
	//header("location:kriteria.php?p=1&id=".$id);
	
	//echo $q;
?>