🤩 File Manager - Mr.X
PHP:
8.3.33
Server:
Apache
OS:
Linux 5.14.0-611.49.1.el9_7.x86_64
User:
websparkit
Navigate
Upload:
Upload
New File
New Folder
Editing:testimonial_edit.php
<?php // admin/testimonial_edit.php require_once '../includes/db.php'; require_once '../includes/functions.php'; $id = null; $client_name = ''; $rating = 5; $comment = ''; $designation = ''; $error = ''; $success = ''; $is_edit = false; // Check if we are editing an existing testimonial if (isset($_GET['id'])) { $id = filter_var($_GET['id'], FILTER_VALIDATE_INT); if ($id !== false) { try { $stmt = $pdo->prepare("SELECT * FROM testimonials WHERE id = ?"); $stmt->execute([$id]); $testimonial = $stmt->fetch(); if ($testimonial) { $client_name = $testimonial['client_name']; $rating = $testimonial['rating']; $comment = $testimonial['comment']; $designation = $testimonial['designation']; $is_edit = true; } else { $error = 'Testimonial not found.'; } } catch (PDOException $e) { $error = 'Database lookup failed: ' . $e->getMessage(); } } else { $error = 'Invalid testimonial ID.'; } } // Handle Form Submission if ($_SERVER['REQUEST_METHOD'] === 'POST') { $client_name = trim($_POST['client_name'] ?? ''); $rating = filter_var($_POST['rating'] ?? 5, FILTER_VALIDATE_INT); $comment = trim($_POST['comment'] ?? ''); $designation = trim($_POST['designation'] ?? ''); // Check fields if (empty($client_name) || empty($comment) || $rating === false || $rating < 1 || $rating > 5) { $error = 'Please fill out all required fields and provide a rating between 1 and 5.'; } else { try { if ($is_edit) { // Update $sql = "UPDATE testimonials SET client_name = :client_name, rating = :rating, comment = :comment, designation = :designation WHERE id = :id"; $stmt = $pdo->prepare($sql); $stmt->execute([ ':client_name' => $client_name, ':rating' => $rating, ':comment' => $comment, ':designation' => $designation, ':id' => $id ]); $success = 'Testimonial updated successfully!'; } else { // Insert $sql = "INSERT INTO testimonials (client_name, rating, comment, designation) VALUES (:client_name, :rating, :comment, :designation)"; $stmt = $pdo->prepare($sql); $stmt->execute([ ':client_name' => $client_name, ':rating' => $rating, ':comment' => $comment, ':designation' => $designation ]); $success = 'Testimonial added successfully!'; // Clear fields on success for new entry $client_name = ''; $rating = 5; $comment = ''; $designation = ''; } } catch (PDOException $e) { $error = 'Failed to save testimonial: ' . $e->getMessage(); } } } include '../includes/admin_header.php'; ?> <div class="row align-items-center mb-4"> <div class="col-sm-6"> <h4 class="mb-0 text-dark"> <i class="fas fa-quote-left me-2 text-royal"></i> <?php echo $is_edit ? 'Edit Testimonial' : 'Add Testimonial'; ?> </h4> </div> <div class="col-sm-6 text-sm-end mt-3 mt-sm-0"> <a href="testimonials.php" class="btn btn-outline-secondary"> <i class="fas fa-arrow-left me-1"></i> Back to Testimonials </a> </div> </div> <?php if (!empty($success)): ?> <div class="alert alert-success border-0 shadow-sm mb-4"> <i class="fas fa-check-circle me-2"></i><?php echo $success; ?> <?php if (!$is_edit): ?> <a href="testimonials.php" class="alert-link ms-2">View in List →</a> <?php endif; ?> </div> <?php endif; ?> <?php if (!empty($error)): ?> <div class="alert alert-danger border-0 shadow-sm mb-4"><i class="fas fa-times-circle me-2"></i><?php echo $error; ?></div> <?php endif; ?> <div class="row"> <div class="col-lg-8"> <div class="card premium-card"> <div class="card-header-royal"> <h5 class="mb-0"> <i class="fas <?php echo $is_edit ? 'fa-edit' : 'fa-plus-circle'; ?> me-2"></i> Testimonial Information </h5> <small class="text-white-50">Specify the customer feedback details. Ratings are displayed as star values.</small> </div> <div class="card-body p-4 p-md-5"> <form method="POST"> <div class="mb-4"> <label for="client_name" class="form-label">Client Name *</label> <div class="input-group"> <span class="input-group-text"><i class="fas fa-user text-muted"></i></span> <input type="text" class="form-control" id="client_name" name="client_name" required value="<?php echo htmlspecialchars($client_name); ?>" placeholder="e.g. John Doe"> </div> </div> <div class="mb-4"> <label for="designation" class="form-label">Client Designation / Role</label> <div class="input-group"> <span class="input-group-text"><i class="fas fa-id-badge text-muted"></i></span> <input type="text" class="form-control" id="designation" name="designation" value="<?php echo htmlspecialchars($designation); ?>" placeholder="e.g. Homeowner, Architect, Interior Designer"> </div> <div class="form-text small text-muted">This will appear under the client name (default is "Homeowner" if empty).</div> </div> <div class="mb-4"> <label for="rating" class="form-label">Rating *</label> <div class="input-group"> <span class="input-group-text"><i class="fas fa-star text-muted"></i></span> <select class="form-select" id="rating" name="rating" required> <option value="5" <?php echo $rating == 5 ? 'selected' : ''; ?>>5 Stars (Excellent)</option> <option value="4" <?php echo $rating == 4 ? 'selected' : ''; ?>>4 Stars (Very Good)</option> <option value="3" <?php echo $rating == 3 ? 'selected' : ''; ?>>3 Stars (Average)</option> <option value="2" <?php echo $rating == 2 ? 'selected' : ''; ?>>2 Stars (Below Average)</option> <option value="1" <?php echo $rating == 1 ? 'selected' : ''; ?>>1 Star (Poor)</option> </select> </div> </div> <div class="mb-4"> <label for="comment" class="form-label">Client Comment *</label> <textarea class="form-control" id="comment" name="comment" rows="6" required placeholder="Write the testimonial comment details here..."><?php echo htmlspecialchars($comment); ?></textarea> </div> <div class="d-grid mt-4"> <button type="submit" class="btn btn-royal py-3 fw-bold text-uppercase"> <i class="fas fa-save me-2"></i> <?php echo $is_edit ? 'Update Testimonial' : 'Save Testimonial'; ?> </button> </div> </form> </div> </div> </div> <!-- Guidelines Help Panel --> <div class="col-lg-4"> <div class="card premium-card bg-light border-0 shadow-sm"> <div class="card-body p-4"> <h6 class="text-royal fw-bold mb-3"><i class="fas fa-info-circle me-2"></i>Writing Guidelines</h6> <ul class="small text-muted ps-3 mb-0"> <li class="mb-2">Keep comments concise (ideally between 150 to 300 characters) so they look neat in the homepage slider.</li> <li class="mb-2">Ensure client names are formatted with correct casing.</li> <li class="mb-2">Ratings directly affect the number of filled stars displayed alongside their name.</li> <li>Designations help establish credibility (e.g., adding "Interior Designer" or "Hotel Owner" showcases commercial client reach).</li> </ul> </div> </div> </div> </div> <?php include '../includes/admin_footer.php'; ?>
Save Changes
Cancel
Create New File
Create New Folder