[ Mini Kiebo ]
Server: Windows NT AKFAR_SERVER 10.0 build 26200 (Windows 10) AMD64
Path:
D:
/
xampp
/
htdocs
/
campus
/
admin
/
[
Home
]
File: berita.php
<?php session_start(); if (!isset($_SESSION['admin_logged_in'])) { header("Location: login.php"); exit; } include '../config/koneksi.php'; // Hapus Berita if (isset($_GET['hapus'])) { $id = $_GET['hapus']; // Hapus gambar fisik jika ada $query = mysqli_query($conn, "SELECT gambar FROM berita WHERE id='$id'"); $data = mysqli_fetch_assoc($query); if ($data['gambar']) { unlink("../uploads/" . $data['gambar']); } mysqli_query($conn, "DELETE FROM berita WHERE id='$id'"); header("Location: berita.php"); } ?> <!DOCTYPE html> <html lang="id"> <head> <title>Kelola Berita</title> <style> body { font-family: sans-serif; padding: 20px; } table { width: 100%; border-collapse: collapse; margin-top: 20px; background: white; } th, td { padding: 12px; border: 1px solid #ddd; text-align: left; } th { background-color: #003366; color: white; } .btn { padding: 5px 10px; text-decoration: none; color: white; border-radius: 3px; } .btn-tambah { background: #27ae60; padding: 10px 20px; } .btn-edit { background: #f39c12; } .btn-hapus { background: #c0392b; } img { width: 50px; height: auto; object-fit: cover; } </style> </head> <body> <h2>Daftar Berita</h2> <a href="tambah_berita.php" class="btn btn-tambah">+ Tambah Berita</a> <a href="index.php" style="margin-left: 10px; text-decoration: none;">Kembali ke Dashboard</a> <table> <thead> <tr> <th>No</th> <th>Gambar</th> <th>Judul</th> <th>Tanggal</th> <th>Aksi</th> </tr> </thead> <tbody> <?php $no = 1; $query = mysqli_query($conn, "SELECT * FROM berita ORDER BY id DESC"); while ($row = mysqli_fetch_assoc($query)) : ?> <tr> <td><?= $no++; ?></td> <td> <?php if($row['gambar']): ?> <img src="../uploads/<?= $row['gambar']; ?>" alt="Gambar"> <?php else: ?> - <?php endif; ?> </td> <td><?= htmlspecialchars($row['judul']); ?></td> <td><?= $row['tanggal']; ?></td> <td> <a href="edit_berita.php?id=<?= $row['id']; ?>" class="btn btn-edit">Edit</a> <a href="berita.php?hapus=<?= $row['id']; ?>" class="btn btn-hapus" onclick="return confirm('Yakin hapus?')">Hapus</a> </td> </tr> <?php endwhile; ?> </tbody> </table> </body> </html>