Viewing File: /home/quiczmwg/public_html/admin/edit-testimonial.php

<?php
// Start the session
session_start();

// Include database connection and other necessary files
include 'head.php';

// Check if ID is provided in the URL
if(isset($_GET['id'])){
    // Retrieve testimonial details based on the ID
    $testimonialId = $_GET['id'];
    // Prepare the SQL statement with a placeholder for the ID
    $stmt = $conn->prepare("SELECT * FROM testimonials WHERE id = ?");
    // Bind the ID parameter to the placeholder
    $stmt->bind_param("i", $testimonialId);
    // Execute the query
    $stmt->execute();
    // Get the result
    $result = $stmt->get_result();
    
    if ($result->num_rows > 0) {
        $row = $result->fetch_assoc();
        // Testimonial details
        $name = $row['name'];
        $title = $row['title'];
        $testimonial = $row['testimonial'];
        $country = $row['country'];
        
        // Check if form is submitted for updating testimonial
        if(isset($_POST['btnUpdateTestimonial'])){
            // Handle form submission and update testimonial details in the database
            // Retrieve form data
            $name = $_POST['name'];
            $title = $_POST['title'];
            $testimonial = $_POST['testimonial'];
            $country = $_POST['country'];

            // Prepare the SQL statement for updating
            $stmt = $conn->prepare("UPDATE testimonials SET name=?, title=?, testimonial=?, country=? WHERE id=?");
            // Bind parameters to the placeholders
            $stmt->bind_param("ssssi", $name, $title, $testimonial, $country, $testimonialId);
            // Execute the update query
            if ($stmt->execute()) {
                echo "Testimonial updated successfully.";
                // Redirect back to manage-testimonials.php or any other page
                header("Location: manage-testimonials.php");
                exit();
            } else {
                echo "Error updating testimonial: " . $conn->error;
            }
        }

        // HTML form for editing testimonial details
        ?>

        <?php include 'head.php'; ?>
        <?php include 'header.php'; ?>

        <body class="skin-default fixed-layout">
            <div id="main-wrapper">
                <?php include 'sidebar.php'; ?>
                <div class="page-wrapper">
                    <section>
                        <div class="">
                            <?php include 'nav1.php'; ?>
                            <div class="container-fluid">
                                <div class="card">
                                    <div class="card-header">
                                        <!-- </?php echo isset($_SESSION['mgs']) ? $_SESSION['mgs'] : "" ?> -->
                                    </div>
                                    <div class="card-body">
                                        <div class="table-responsive">
                                            <table class="table">
                                                <tbody>
                                                    <!-- HTML Form for updating testimonial -->
                                                    <h2>Edit Testimonial</h2>
                                                    <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]) . "?id=" . $testimonialId; ?>" method="post">
                                                        <input type="hidden" name="testimonialId" value="<?php echo $testimonialId; ?>">
                                                        <label for="name">Name:</label><br>
                                                        <input type="text" id="name" class="form-control" name="name" value="<?php echo $name; ?>"><br>
                                                        <label for="title">Title:</label><br>
                                                        <input type="text" id="title" class="form-control" name="title" value="<?php echo $title; ?>"><br>
                                                        <label for="testimonial">Testimonial:</label><br>
                                                        <textarea id="testimonial" class="form-control" name="testimonial"><?php echo $testimonial; ?></textarea><br>
                                                        <label for="country">Country:</label><br>
                                                        <input type="text" id="country" class="form-control" name="country" value="<?php echo $country; ?>"><br><br>
                                                        <input type="submit" name="btnUpdateTestimonial" class="btn btn-success" value="Update Testimonial">
                                                    </form>
                                                </tbody>
                                            </table>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </section>
                </div>
            </div>
            <?php include 'footer.php'; ?>
        </body>
        </html>
        <?php
    } else {
        echo "Testimonial not found.";
    }
} else {
    echo "Testimonial ID not provided.";
}
?>
Back to Directory File Manager
<