File manager - Edit - /home/monara/public_html/BenHoldings_web/assets/php/view_messages.php
Back
<?php // view_messages.php // Use absolute path relative to this file $config_path = __DIR__ . '/config.php'; if(!file_exists($config_path)) { die("Error: Configuration file not found at $config_path"); } include_once $config_path; // Check if connection is established if(!isset($conn) || !$conn) { die("Error: Database connection not established. Check config.php"); } // Handle delete request if(isset($_GET['delete']) && is_numeric($_GET['delete'])) { $id = $_GET['delete']; $stmt = $conn->prepare("DELETE FROM contacts WHERE id = ?"); $stmt->bind_param("i", $id); $stmt->execute(); $stmt->close(); header("Location: view_messages.php"); exit; } // Fetch all messages $result = $conn->query("SELECT * FROM contacts ORDER BY created_at DESC"); if(!$result) { die("Error: Database query failed - " . $conn->error); } ?> <!DOCTYPE html> <html> <head> <title>View Messages</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet"> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script> </head> <body> <div class="container mt-5"> <h2 class="mb-4">Contact Messages</h2> <?php if($result->num_rows > 0): ?> <div class="table-responsive"> <table class="table table-striped table-hover"> <thead class="table-dark"> <tr> <th>ID</th> <th>Name</th> <th>Email</th> <th>Message</th> <th>Date</th> <th>Actions</th> </tr> </thead> <tbody> <?php while($row = $result->fetch_assoc()): ?> <tr> <td><?php echo htmlspecialchars($row['id']); ?></td> <td><?php echo htmlspecialchars($row['name']); ?></td> <td><?php echo htmlspecialchars($row['email']); ?></td> <td><?php echo htmlspecialchars($row['message']); ?></td> <td><?php echo htmlspecialchars($row['created_at']); ?></td> <td> <a href="?delete=<?php echo $row['id']; ?>" class="btn btn-danger btn-sm" onclick="return confirm('Are you sure you want to delete this message?')"> Delete </a> </td> </tr> <?php endwhile; ?> </tbody> </table> </div> <?php else: ?> <div class="alert alert-info">No messages found.</div> <?php endif; ?> <?php $result->close(); $conn->close(); ?> </div> </body> </html>
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0 |
proxy
|
phpinfo
|
Settings