-
Notifications
You must be signed in to change notification settings - Fork 2
/
ilansil.php
73 lines (67 loc) · 2.31 KB
/
ilansil.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
include "header.php";
if ($_SESSION["kullanici_loginkey"] == "") {
// oturum açılmamışsa login.php sayfasına git
header("Location: index.php");
}
// veritabanı bağlantı dosyasını dahil et
include 'config/vtabani.php';
try {
// kaydın id bilgisini al
$id=isset($_GET['id']) ? $_GET['id'] : die('HATA: Id bilgisi bulunamadı.');
// silinecek kayıt bilgilerini oku
// seçme sorgusunu hazırla
$sorgu = "SELECT id, resim, resim_iki, resim_uc, resim_dort FROM urunler WHERE id = ? LIMIT 0,1";
$stmt = $con->prepare( $sorgu );
// id parametresini bağla (? işaretini id değeri ile değiştir)
$stmt->bindParam(1, $id);
// sorguyu çalıştır
$stmt->execute();
$kayit = $stmt->fetch(PDO::FETCH_ASSOC);
// okunan resim bilgilerini bir değişkene kaydet
$resim = $kayit['resim'];
$resim_iki = $kayit['resim_iki'];
$resim_uc = $kayit['resim_uc'];
$resim_dort = $kayit['resim_dort'];
// silme sorguları...
$sorgu = "DELETE FROM urunler WHERE id = ?";
$stmt = $con->prepare($sorgu);
$stmt->bindParam(1, $id);
$sorgu2 = "DELETE FROM evbilgi WHERE ev_urun_id = ?";
$stmt2 = $con->prepare($sorgu2);
$stmt2->bindParam(1, $id);
$sorgu3 = "DELETE FROM arsabilgi WHERE arsa_urun_id = ?";
$stmt3 = $con->prepare($sorgu3);
$stmt3->bindParam(1, $id);
// sorguyu çalıştır
if($stmt->execute() && ($stmt2->execute() || $stmt3->execute())){
// kayıt listeleme sayfasına yönlendir
// ve kullanıcıya kaydın silindiğini
// kayda ait resim varsa sunucudan sil
if(!empty($resim)){
$silinecek_resim = "content/images/".$resim;
if (file_exists($silinecek_resim)) unlink($silinecek_resim);
}
if(!empty($resim_iki)){
$silinecek_resim = "content/images/".$resim_iki;
if (file_exists($silinecek_resim)) unlink($silinecek_resim);
}
if(!empty($resim_uc)){
$silinecek_resim = "content/images/".$resim_uc;
if (file_exists($silinecek_resim)) unlink($silinecek_resim);
}
if(!empty($resim_dort)){
$silinecek_resim = "content/images/".$resim_dort;
if (file_exists($silinecek_resim)) unlink($silinecek_resim);
}
header('Location: ilanlarim.php?islem=silindi');
} // veya silinemediğini bildir
else{
header('Location: ilanlarim.php?islem=silinemedi');
}
}
// hata varsa göster
catch(PDOException $exception){
die('HATA: ' . $exception->getMessage());
}
?>