D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home3
/
encodto1
/
attraction.encodersunlimited.com
/
attadminraction
/
Filename :
edit_testimonial.php
back
Copy
<?php include 'config.php'; // Include database connection file // Get the testimonial ID from the URL if (isset($_GET['id'])) { $testimonial_id = $_GET['id']; // Fetch the testimonial data from the database $query = "SELECT * FROM testimonial WHERE id = ?"; $stmt = $conn->prepare($query); $stmt->bind_param('i', $testimonial_id); $stmt->execute(); $result = $stmt->get_result(); $testimonial = $result->fetch_assoc(); } // Handle form submission and image upload for updating the testimonial if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['updatetestimonial'])) { $name = $_POST['name']; $comment = $_POST['comment']; $designation = $_POST['designation']; $testimonial_id = $_POST['testimonial_id']; // Check if a new image is uploaded if (isset($_FILES['image']) && $_FILES['image']['error'] == UPLOAD_ERR_OK) { $imagePath = image_upload($_FILES['image']); if ($imagePath !== false) { // Update the testimonial with a new image $query = "UPDATE testimonial SET name = ?, image = ?, comment = ?, designation = ? WHERE id = ?"; $stmt = $conn->prepare($query); $stmt->bind_param('ssssi', $name, $imagePath, $comment, $designation, $testimonial_id); } } else { // Update the testimonial without changing the image $query = "UPDATE testimonial SET name = ?, comment = ?, designation = ? WHERE id = ?"; $stmt = $conn->prepare($query); $stmt->bind_param('sssi', $name, $comment, $designation, $testimonial_id); } if ($stmt->execute()) { header("Location: testimonial.php"); } else { echo "Error: " . $stmt->error; } } ?> <!DOCTYPE html> <html lang="en"> <head> <?php include 'style.php'; ?> </head> <body> <!-- loader starts--> <div class="loader-wrapper"> <div class="loader"> <div class="box"></div> <div class="box"></div> <div class="box"></div> <div class="box"></div> <div class="box"></div> </div> </div> <!-- loader ends--> <!-- tap on top starts--> <div class="tap-top"><i data-feather="chevrons-up"></i></div> <!-- tap on tap ends--> <!-- page-wrapper Start--> <div class="page-wrapper default-wrapper" id="pageWrapper"> <!-- Page Header Start--> <!-- Page Header Ends --> <!-- Page Body Start--> <div class="page-body-wrapper default-menu default-menu"> <!-- Page Sidebar Start--> <?php include 'sidebar.php'; ?> <!-- Page Sidebar Ends--> <div class="page-body"> <div class="container-fluid"> <div class="page-title"> <div class="row"> <div class="col-sm-6 ps-0"> <h3>Edit Testimonial</h3> </div> </div> </div> </div> <!-- Container-fluid starts--> <form action="edit_testimonial.php?id=<?php echo $testimonial_id; ?>" method="POST" enctype="multipart/form-data"> <div class="container-fluid"> <div class="row"> <div class="col-sm-12"> <div class="card"> <div class="card-body"> <div class="form theme-form"> <input type="hidden" name="testimonial_id" value="<?php echo $testimonial['id']; ?>"> <div class="row"> <div class="col"> <div class="mb-3"> <label>Name</label> <input class="form-control" type="text" name="name" value="<?php echo $testimonial['name']; ?>" required> </div> </div> </div> <div class="row"> <div class="col"> <div class="mb-3"> <label>Comment</label> <textarea class="form-control" name="comment" rows="4" required><?php echo $testimonial['comment']; ?></textarea> </div> </div> </div> <div class="row"> <div class="col"> <div class="mb-3"> <label>Designation</label> <input class="form-control" type="text" name="designation" value="<?php echo $testimonial['designation']; ?>" required> </div> </div> </div> <div class="row"> <div class="col"> <div class="mb-3"> <label>Upload Image</label> <h4>Drop files here or click to upload.</h4> <input type="file" name="image" class="form-control" accept=".jpg, .jpeg, .png, .svg"> <small>Current Image: <img src="uploads/<?php echo $testimonial['image']; ?>" alt="Current Image" width="50"></small> </div> </div> </div> <div class="row"> <div class="col"> <button type="submit" class="btn btn-success" name="updatetestimonial">Update Testimonial</button> <button type="reset" class="btn btn-outline-secondary">Cancel</button> </div> </div> </div> </div> </div> </div> </div> </div> </form> <!-- Container-fluid Ends--> </div> <!-- footer start--> <?php include 'footer.php'; ?> </div> </div> </body> </html>