

<?php 
include("inc/vt.php"); 
$iller =$_POST['id'];

if($iller){
	$ilceler = $dbh -> prepare("SELECT * FROM ilce WHERE  ilce_sehirkey in ($iller) ");
	$ilceler-> execute(array());
	$ilceler = $ilceler->fetchAll(PDO::FETCH_OBJ);


	foreach ($ilceler as $ilce ) {
		echo ' <option value="'.$ilce->ilce_key.'" selected>'.$ilce->ilce_title.'</option>';
	}
}

if($_GET['islem']=="adres-guncelleme"){
	$iller =$_POST['iller'];
	$ilceler =$_POST['ilceler'];
	$ilp= explode(",", $iller);
	$ilcep= explode(",", $ilceler);

	$guncelle = $dbh -> prepare("UPDATE sehir SET aktif = ? ");
	$guncelle->execute([0]);

	$guncelle = $dbh -> prepare("UPDATE ilce SET aktif = ? ");
	$guncelle->execute([0]);

	$guncelle = $dbh -> prepare("UPDATE mahalle SET aktif = ? ");
	$guncelle->execute([0]);
	
	foreach ($ilp as $ilpd) {
		$guncelle = $dbh -> prepare("UPDATE sehir SET aktif = ? WHERE sehir_key = ?");
		$guncelle->execute([1, $ilpd]);
	}

	foreach ($ilcep as $ilcd) {
		$guncelle = $dbh -> prepare("UPDATE ilce SET aktif = ? WHERE ilce_key = ?");
		$guncelle->execute([1, $ilcd]);

		$guncelle = $dbh -> prepare("UPDATE mahalle SET aktif = ? WHERE mahalle_ilcekey = ?");
		$guncelle->execute([1, $ilcd]);

	}




	header("location:adres-yonetimi.php");


}
?>
