D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home3
/
encodto1
/
public_html
/
encoadminders
/
Filename :
website_portfolio.php
back
Copy
<?php session_start(); include 'config.php'; // Check if the user is logged in if (!isset($_SESSION['admin_name'])) { echo '<script>window.location.href = "login.php";</script>'; exit; } // Handle delete request if (isset($_GET['delete_id'])) { $delete_id = $_GET['delete_id']; // Fetch the image file name to delete from the server $query = "SELECT image FROM website_portfolio WHERE id = ?"; $stmt = mysqli_prepare($conn, $query); mysqli_stmt_bind_param($stmt, "i", $delete_id); mysqli_stmt_execute($stmt); mysqli_stmt_bind_result($stmt, $image); mysqli_stmt_fetch($stmt); mysqli_stmt_close($stmt); // Delete the image file from the server if ($image && file_exists("uploads/website/" . $image)) { unlink("uploads/website/" . $image); } // Delete the record from the database $delete_query = "DELETE FROM website_portfolio WHERE id = ?"; $stmt = mysqli_prepare($conn, $delete_query); mysqli_stmt_bind_param($stmt, "i", $delete_id); if (mysqli_stmt_execute($stmt)) { echo '<script>alert("Portfolio item deleted successfully."); window.location.href = "website_portfolio.php";</script>'; } else { echo '<script>alert("Error deleting portfolio item.");</script>'; } mysqli_stmt_close($stmt); } // Fetch all website portfolio items $query = "SELECT * FROM website_portfolio ORDER BY id DESC"; $result = mysqli_query($conn, $query); if (!$result) { die("Query failed: " . mysqli_error($conn)); } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Website Portfolio</title> <?php include 'style.php'; ?> <style> .portfolio-container { max-width: 1200px; margin: 0 auto; background: #fff; padding: 20px; border-radius: 8px; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1); } table { width: 100%; border-collapse: collapse; margin: 20px 0; font-size: 16px; } thead { background-color: #34495e; color: #fff; } thead th { text-align: left; padding: 10px; } tbody tr { border-bottom: 1px solid #ddd; } tbody tr:hover { background-color: #f1f1f1; } tbody td { padding: 10px; vertical-align: middle; } .gallery-image { max-width: 100px; height: auto; border-radius: 5px; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); } .action-buttons a { text-decoration: none; padding: 8px 12px; margin-right: 5px; font-size: 14px; border-radius: 5px; transition: background-color 0.3s ease; } .btn-edit { background-color: #3498db; color: #fff; } .btn-edit:hover { background-color: #2980b9; } .btn-delete { background-color: #e74c3c; color: #fff; } .btn-delete:hover { background-color: #c0392b; } footer { text-align: center; margin-top: 20px; font-size: 14px; color: #7f8c8d; } footer a { color: #3498db; text-decoration: none; } @media (max-width: 768px) { table { font-size: 14px; } .gallery-image { max-width: 80px; } .action-buttons a { font-size: 12px; padding: 5px 10px; } } </style> </head> <body> <?php include 'sidebar.php'; ?> <div class="home-section"> <div class="portfolio-container"> <div class="portfolio-header"> <h1>Website Portfolio</h1> <a href="add_website.php" class="btn-add">Add New Website</a> </div> <table> <thead> <tr> <th>ID</th> <th>Image</th> <th>Name</th> <th>Category</th> <th>Actions</th> </tr> </thead> <tbody> <?php while ($row = mysqli_fetch_assoc($result)) : ?> <tr> <td><?php echo $row['id']; ?></td> <td> <img src="uploads/website/<?php echo $row['image']; ?>" alt="Website Image" class="gallery-image"> </td> <td><?php echo htmlspecialchars($row['name']); ?></td> <td><?php echo htmlspecialchars($row['category']); ?></td> <td class="action-buttons"> <a href="edit_website.php?id=<?php echo $row['id']; ?>" class="btn-edit">Edit</a> <a href="?delete_id=<?php echo $row['id']; ?>" class="btn-delete" onclick="return confirm('Are you sure?');">Delete</a> </td> </tr> <?php endwhile; ?> </tbody> </table> </div> </div> <?php include('footer.php'); ?> </body> </html>