<?php


if(empty($_GET['Kode']))
{
	echo "<b>Data yang dihapus tidak ada</b>";
}
else 
{
	// Membaca Kode dari URL
	$Kode	= $_GET['Kode'];
	// $txtNamaFile=$_GET['txtNamaFile'];

	# MENGHAPUS GAMBAR/FOTO, Caranya dengan membaca file gambar
	$mySql = "SELECT * FROM siswa WHERE nis='$Kode'";
	$myQry = mysql_query($mySql, $koneksidb)  or die ("Query salah : ".mysql_error());
	$myData= mysql_fetch_array($myQry);
	if(! $myData['foto']=="") 
	{
		if(file_exists("../foto_siswa/".$myData['foto'])) 
		{
			// Jika file gambarnya ada, akan dihapus
			unlink("../foto_siswa/".$myData['foto']); 
		}
	}

	$sqlDelete = "DELETE FROM siswa WHERE nis='".$_GET['Kode']."'";
	$qryDelete = mysql_query($sqlDelete, $koneksidb) or die ("Eror hapus data".mysql_error());
	if($qryDelete)
	{
		$sqlDelete2 = "DELETE FROM kelas_siswa WHERE nis='".$_GET['Kode']."' AND kdkelas='".$_GET['KodeKelas']."'";
		$qryDelete2 = mysql_query($sqlDelete2, $koneksidb) or die ("Eror hapus data".mysql_error());
		echo "<meta http-equiv='refresh' content='0; url=?page=Data-Siswa'>";
	}
}

?>