D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home3
/
encodto1
/
public_html
/
encoadminders
/
Filename :
testimonial.php
back
Copy
<?php session_start(); include 'config.php'; if (!isset($_SESSION['admin_name'])) { echo '<script>window.location.href = "login.php";</script>'; exit; } // Handle delete functionality if (isset($_GET['delete_id'])) { $testimonial_id = $_GET['delete_id']; // Fetch the testimonial to get the image name $query = "SELECT image FROM testimonials WHERE testimonial_id = ?"; $stmt = mysqli_prepare($conn, $query); mysqli_stmt_bind_param($stmt, 'i', $testimonial_id); mysqli_stmt_execute($stmt); $result = mysqli_stmt_get_result($stmt); $testimonial = mysqli_fetch_assoc($result); if ($testimonial) { // Delete the image file $image_path = 'uploads/testimonials/' . $testimonial['image']; if (file_exists($image_path)) { unlink($image_path); } // Delete the testimonial from the database $delete_query = "DELETE FROM testimonials WHERE testimonial_id = ?"; $delete_stmt = mysqli_prepare($conn, $delete_query); mysqli_stmt_bind_param($delete_stmt, 'i', $testimonial_id); if (mysqli_stmt_execute($delete_stmt)) { echo '<script>alert("Testimonial deleted successfully!"); window.location.href = "testimonial.php";</script>'; } else { echo '<script>alert("Failed to delete testimonial!");</script>'; } } else { echo '<script>alert("Testimonial not found!");</script>'; } } // Fetch testimonials from the database $query = "SELECT * FROM testimonials ORDER BY created_at DESC"; $result = mysqli_query($conn, $query); ?> <!DOCTYPE html> <html lang="en"> <head> <?php require('style.php'); ?> <title>Testimonials</title> <style> /* Container Styles */ .home-section { max-width: 1200px; margin: 40px auto; padding: 20px; background-color: #ffffff; border-radius: 10px; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.1); font-family: 'Poppins', sans-serif; left: 20px; } /* Header Section */ .gallery-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; } .gallery-header h1 { font-size: 24px; color: #333; } .btn-add { background-color: #007bff; color: #fff; padding: 10px 20px; border-radius: 8px; text-decoration: none; font-size: 14px; font-weight: bold; transition: background-color 0.3s ease; } .btn-add:hover { background-color: #0056b3; color: white; } /* Table Styles */ .testimonial-table-container { overflow-x: auto; } table { width: 100%; border-collapse: collapse; margin-top: 20px; font-size: 14px; } thead { background-color: #f4f4f4; } thead th { padding: 12px; text-align: left; color: #555; font-weight: 600; } tbody td { padding: 10px 12px; border-bottom: 1px solid #ddd; color: #555; vertical-align: middle; } tbody tr:hover { background-color: #f9f9f9; } tbody img { border-radius: 8px; display: block; max-width: 100px; height: auto; object-fit: cover; } /* Action Buttons */ .btn-edit, .btn-delete { display: inline-block; padding: 8px 12px; font-size: 12px; border-radius: 8px; text-decoration: none; margin-right: 5px; transition: all 0.3s ease; } .btn-edit { background-color: #28a745; color: white; } .btn-edit:hover { background-color: #218838; color: #fff; } .btn-delete { background-color: #dc3545; color: #fff; } .btn-delete:hover { background-color: #c82333; color: white; } /* Responsive Design */ @media (max-width: 768px) { table { font-size: 12px; } .btn-add, .btn-edit, .btn-delete { padding: 8px 10px; font-size: 12px; } } </style> </head> <body> <?php include('sidebar.php') ?> <div class="home-section"> <div class="gallery-header"> <h1>All Testimonials</h1> <a href="add_testimonial.php" class="btn-add">Add Testimonial</a> </div> <div class="testimonial-table-container"> <table> <thead> <tr> <th>Testimonial ID</th> <th>Name</th> <th>Designation</th> <th>Comment</th> <th>Image</th> <th>Created At</th> <th>Actions</th> </tr> </thead> <tbody> <?php while ($row = mysqli_fetch_assoc($result)) : ?> <tr> <td><?php echo htmlspecialchars($row['testimonial_id']); ?></td> <td><?php echo htmlspecialchars($row['name']); ?></td> <td><?php echo htmlspecialchars($row['designation']); ?></td> <td><?php echo htmlspecialchars($row['comment']); ?></td> <td> <img src="uploads/testimonials/<?php echo htmlspecialchars($row['image']); ?>" alt="Image" width="100"> </td> <td><?php echo htmlspecialchars($row['created_at']); ?></td> <td> <a href="edit_testimonial.php?id=<?php echo $row['testimonial_id']; ?>" class="btn-edit">Edit</a> <a href="testimonial.php?delete_id=<?php echo $row['testimonial_id']; ?>" class="btn-delete" onclick="return confirm('Are you sure you want to delete this testimonial?');">Delete</a> </td> </tr> <?php endwhile; ?> </tbody> </table> </div> </div> <?php include('footer.php') ?> </body> </html>