-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin_urunler.php
214 lines (187 loc) · 6.08 KB
/
admin_urunler.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<?php
session_start();
// Admin giriş kontrolü
if (!isset($_SESSION['admin_id'])) {
header("Location: admin_login.php");
exit();
}
// Veritabanı bağlantısı
$servername = "localhost";
$username = "root";
$password = ""; // Veritabanı şifreniz
$dbname = "primefit"; // Veritabanı adı
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Bağlantı hatası: " . $conn->connect_error);
}
// Yeni ürün ekleme
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['ekle'])) {
$isim = $_POST['isim'];
$fiyat = $_POST['fiyat'];
$sql = "INSERT INTO urunler (isim, fiyat) VALUES ('$isim', '$fiyat')";
if ($conn->query($sql) === TRUE) {
echo "<script>alert('Ürün başarıyla eklendi!');</script>";
} else {
echo "<script>alert('Ürün eklenirken hata oluştu: " . $conn->error . "');</script>";
}
}
// Ürün silme
if (isset($_GET['sil'])) {
$urun_id = $_GET['sil'];
$sql = "DELETE FROM urunler WHERE urun_id = $urun_id";
if ($conn->query($sql) === TRUE) {
echo "<script>alert('Ürün başarıyla silindi!');</script>";
} else {
echo "<script>alert('Ürün silinirken hata oluştu: " . $conn->error . "');</script>";
}
}
// Ürün güncelleme
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['guncelle'])) {
$urun_id = $_POST['urun_id'];
$isim = $_POST['isim'];
$fiyat = $_POST['fiyat'];
$sql = "UPDATE urunler SET isim='$isim', fiyat='$fiyat' WHERE urun_id=$urun_id";
if ($conn->query($sql) === TRUE) {
echo "<script>alert('Ürün başarıyla güncellendi!');</script>";
} else {
echo "<script>alert('Ürün güncellenirken hata oluştu: " . $conn->error . "');</script>";
}
}
// Ürünleri veritabanından çek
$sql = "SELECT * FROM urunler";
$result = $conn->query($sql);
$conn->close();
?>
<!DOCTYPE html>
<html lang="tr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ürün Yönetimi</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background: #f4f4f4;
}
.container {
width: 90%;
margin: auto;
margin-top: 50px;
}
table {
width: 100%;
border-collapse: collapse;
background: #fff;
margin-bottom: 20px;
}
table th, table td {
border: 1px solid #ddd;
padding: 12px;
text-align: left;
}
table th {
background-color: #f77f00;
color: #fff;
}
form {
display: flex;
gap: 10px;
flex-wrap: wrap;
margin-bottom: 20px;
}
form input[type="text"], form input[type="number"] {
padding: 10px;
font-size: 16px;
border: 1px solid #ddd;
border-radius: 4px;
width: calc(100% - 20px);
}
form button {
padding: 10px 20px;
background-color: #f77f00;
color: #fff;
border: none;
border-radius: 4px;
cursor: pointer;
}
form button:hover {
background-color: #f57c00;
}
.delete-btn {
background-color: #e74c3c;
color: white;
padding: 5px 10px;
border-radius: 4px;
text-decoration: none;
}
.delete-btn:hover {
background-color: #c0392b;
}
.back-btn {
padding: 10px 20px;
background-color: #3498db;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
text-decoration: none;
}
.back-btn:hover {
background-color: #2980b9;
}
</style>
</head>
<body>
<div class="container">
<a href="admin_index.php" style="text-decoration: none;">
<button class="back-btn">Ana Sayfaya Dön</button>
</a>
<h1>Ürün Yönetimi</h1>
<!-- Yeni Ürün Ekleme -->
<form method="POST">
<input type="text" name="isim" placeholder="Ürün İsmi" required>
<input type="number" name="fiyat" placeholder="Ürün Fiyatı" required>
<button type="submit" name="ekle">Ürün Ekle</button>
</form>
<!-- Ürünler Tablosu -->
<table>
<thead>
<tr>
<th>Ürün ID</th>
<th>İsim</th>
<th>Fiyat</th>
<th>İşlemler</th>
</tr>
</thead>
<tbody>
<?php if ($result->num_rows > 0): ?>
<?php while ($row = $result->fetch_assoc()): ?>
<tr>
<form method="POST">
<td><?php echo $row['urun_id']; ?></td>
<td>
<input type="text" name="isim" value="<?php echo $row['isim']; ?>">
</td>
<td>
<input type="number" name="fiyat" value="<?php echo $row['fiyat']; ?>">
</td>
<td>
<input type="hidden" name="urun_id" value="<?php echo $row['urun_id']; ?>">
<button type="submit" name="guncelle">Güncelle</button>
<a href="?sil=<?php echo $row['urun_id']; ?>" class="delete-btn">Sil</a>
</td>
</form>
</tr>
<?php endwhile; ?>
<?php else: ?>
<tr>
<td colspan="4">Kayıtlı ürün bulunamadı.</td>
</tr>
<?php endif; ?>
</tbody>
</table>
</div>
</body>
</html>