File manager - Edit - /home/familylifersmpc/htdocs/www.familylifersmpc.com/announcement_form.php
Back
<?php error_reporting(0); include('editor-includes/web-config.php'); $conn = new mysqli($host, $user, $pass, $dbname); if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } // Handle delete request if (isset($_GET['delete_id'])) { $deleteId = intval($_GET['delete_id']); // Get image name before deleting $result = $conn->query("SELECT ImageName FROM announcementtbl WHERE ID = $deleteId"); $row = $result->fetch_assoc(); if (!empty($row['ImageName'])) { $imagePath = "UPLOADS_ANNOUNCEMENTS/" . $row['ImageName']; if (file_exists($imagePath)) { unlink($imagePath); } } // Delete from database $conn->query("DELETE FROM announcementtbl WHERE ID = $deleteId"); echo "<div class='alert alert-success text-center'>Announcement deleted successfully!</div>"; } // Handle new announcement submission if ($_SERVER['REQUEST_METHOD'] == 'POST') { $title = $conn->real_escape_string($_POST['title']); $description = $conn->real_escape_string($_POST['description']); $imagePos = $conn->real_escape_string($_POST['image_position']); // Image upload $imageName = ''; if (!empty($_FILES['image']['name'])) { $uploadDir = "UPLOADS_ANNOUNCEMENTS/"; if (!is_dir($uploadDir)) mkdir($uploadDir, 0777, true); $imageName = time() . "_" . basename($_FILES['image']['name']); $targetFile = $uploadDir . $imageName; move_uploaded_file($_FILES['image']['tmp_name'], $targetFile); } $conn->query("INSERT INTO announcementtbl (Title, Description, ImageName, ImagePosition) VALUES ('$title', '$description', '$imageName', '$imagePos')"); echo "<div class='alert alert-success text-center'>Announcement posted successfully!</div>"; } // --- Pagination Setup --- $postsPerPage = 5; $page = isset($_GET['page']) ? (int) $_GET['page'] : 1; if ($page < 1) $page = 1; $offset = ($page - 1) * $postsPerPage; // Count total announcements $totalResult = $conn->query("SELECT COUNT(*) as total FROM announcementtbl"); $totalRow = $totalResult->fetch_assoc(); $totalPosts = $totalRow['total']; $totalPages = ceil($totalPosts / $postsPerPage); // Fetch announcements for current page $result = $conn->query("SELECT * FROM announcementtbl ORDER BY ID DESC LIMIT $offset, $postsPerPage"); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Create Announcement</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet"> <style> body { background: #f8f9fa; } .form-container { max-width: 600px; margin: 50px auto 30px; background: #fff; padding: 20px; border-radius: 15px; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1); } .announcement-card { max-width: 900px; margin: 20px auto; background: #fff; border-radius: 15px; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1); padding: 20px; } .announcement-img { width: 100%; max-width: 400px; border-radius: 10px; object-fit: cover; } .row-align { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; } @media (max-width: 768px) { .row-align { flex-direction: column; text-align: center; } .announcement-img { max-width: 100%; } } </style> </head> <body> <div class="container"> <!-- Announcement Form --> <div class="form-container"> <h3 class="mb-3 text-center">Create Announcement</h3> <form method="post" enctype="multipart/form-data"> <div class="mb-3"> <label class="form-label">Title</label> <input type="text" name="title" class="form-control" required> </div> <div class="mb-3"> <label class="form-label">Description</label> <textarea name="description" class="form-control" rows="4" required></textarea> </div> <div class="mb-3"> <label class="form-label">Image (optional)</label> <input type="file" name="image" class="form-control"> </div> <div class="mb-3"> <label class="form-label">Image Position</label> <select name="image_position" class="form-select" required> <option value="left">Left</option> <option value="right">Right</option> </select> </div> <button type="submit" class="btn btn-success w-100">Post Announcement</button> </form> </div> </div> </body> </html> <?php $conn->close(); ?>
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.01 |
proxy
|
phpinfo
|
Settings