prepare("DELETE FROM testimonials WHERE id = :id"); $stmt->execute(['id' => $delete_id]); header("Location: " . BASE_URL . "admin/testimonials.php?success=deleted"); exit(); } catch (PDOException $e) { $error_msg = "Failed to delete testimonial: " . $e->getMessage(); } } // Add/Edit Form submit logic if (isset($_POST['submit_testimonial'])) { $client_name = trim($_POST['client_name']); $designation = trim($_POST['designation']); $comment = trim($_POST['comment']); $rating = intval($_POST['rating']); if (empty($client_name) || empty($comment)) { $error_msg = "Client Name and Comment are required fields."; } else { try { if ($action === 'add') { $stmt = $pdo->prepare("INSERT INTO testimonials (client_name, designation, comment, rating) VALUES (:client_name, :designation, :comment, :rating)"); $stmt->execute([ 'client_name' => $client_name, 'designation' => $designation, 'comment' => $comment, 'rating' => $rating ]); header("Location: " . BASE_URL . "admin/testimonials.php?success=added"); exit(); } elseif ($action === 'edit') { $stmt = $pdo->prepare("UPDATE testimonials SET client_name = :client_name, designation = :designation, comment = :comment, rating = :rating WHERE id = :id"); $stmt->execute([ 'client_name' => $client_name, 'designation' => $designation, 'comment' => $comment, 'rating' => $rating, 'id' => $id ]); header("Location: " . BASE_URL . "admin/testimonials.php?success=updated"); exit(); } } catch (PDOException $e) { $error_msg = "Database error: " . $e->getMessage(); } } } // Edit Form preload details $edit_data = ['client_name' => '', 'designation' => '', 'comment' => '', 'rating' => 5]; if ($action === 'edit' && $id > 0) { try { $stmt = $pdo->prepare("SELECT * FROM testimonials WHERE id = :id"); $stmt->execute(['id' => $id]); $edit_data = $stmt->fetch(); if (!$edit_data) { header("Location: " . BASE_URL . "admin/testimonials.php"); exit(); } } catch (PDOException $e) { $error_msg = "Error loading testimonial: " . $e->getMessage(); } } // Fetch all testimonials $all_testimonials = []; try { $stmt = $pdo->query("SELECT * FROM testimonials ORDER BY id DESC"); $all_testimonials = $stmt->fetchAll(); } catch (PDOException $e) { // offline mock } require_once __DIR__ . '/header.php'; require_once __DIR__ . '/navbar.php'; ?>

Manage Testimonials

Add Testimonial Back to List
Client Name Designation / Firm Comment Rating Actions
" 70 ? '...' : '' ?>"
No reviews recorded.

Add Testimonial' : 'Edit Testimonial Details' ?>

Cancel