D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home3
/
encodto1
/
tresboutique.in
/
tresadmin
/
Filename :
edit_testimonial.php
back
Copy
<?php include 'config.php'; // Check if the testimonial_id is set in the URL if (isset($_GET['testimonial_id'])) { $testimonial_id = $_GET['testimonial_id']; // Fetch existing testimonial data $query = "SELECT * FROM testimonial WHERE testimonial_id = '$testimonial_id'"; $result = mysqli_query($conn, $query); if ($result && mysqli_num_rows($result) > 0) { $testimonial = mysqli_fetch_assoc($result); } else { echo '<script>alert("Testimonial not found."); window.location.href = "testimonials.php";</script>'; exit; } } else { echo '<script>alert("No testimonial ID provided."); window.location.href = "testimonials.php";</script>'; exit; } // Handle form submission if ($_SERVER['REQUEST_METHOD'] === 'POST') { $testimonial_name = mysqli_real_escape_string($conn, $_POST['testimonial_name']); $testimonial_designation = mysqli_real_escape_string($conn, $_POST['testimonial_designation']); $testimonial_comment = mysqli_real_escape_string($conn, $_POST['testimonial_comment']); $created_at = $testimonial['created_at']; // Keep the original creation time // Handle image upload $testimonial_image = $testimonial['testimonial_image']; // Keep the current image by default if (!empty($_FILES['testimonial_image']['name'])) { $targetDir = "uploads/testimonials/"; $fileName = basename($_FILES['testimonial_image']['name']); $targetFilePath = $targetDir . $fileName; $check = getimagesize($_FILES['testimonial_image']['tmp_name']); if ($check === false) { echo '<script>alert("File is not an image.");</script>'; } elseif ($_FILES['testimonial_image']['size'] > 5000000) { // 5MB limit echo '<script>alert("File is too large.");</script>'; } else { if (move_uploaded_file($_FILES['testimonial_image']['tmp_name'], $targetFilePath)) { $testimonial_image = $fileName; } else { echo '<script>alert("Error uploading image.");</script>'; } } } // Update testimonial in the database $updateQuery = "UPDATE testimonial SET testimonial_name = '$testimonial_name', testimonial_image = '$testimonial_image', testimonial_designation = '$testimonial_designation', testimonial_comment = '$testimonial_comment', created_at = '$created_at' WHERE testimonial_id = '$testimonial_id'"; if (mysqli_query($conn, $updateQuery)) { echo '<script>alert("Testimonial updated successfully."); window.location.href = "testimonials.php";</script>'; } else { echo '<script>alert("Error updating testimonial: ' . mysqli_error($conn) . '");</script>'; } } ?> <!DOCTYPE html> <html lang="en"> <head> <?php require('style.php'); ?> </head> <body> <div class="page-wrapper compact-wrapper" id="pageWrapper"> <div class="page-body-wrapper"> <?php require('sidebar.php'); ?> <div class="page-body"> <div class="container-fluid"> <div class="page-title"> <h3>Edit Testimonial</h3> </div> <div class="container"> <form method="POST" enctype="multipart/form-data"> <div class="row"> <div class="col-md-6"> <div class="mb-3"> <label for="testimonial_name" class="form-label">Testimonial Name</label> <input type="text" name="testimonial_name" id="testimonial_name" class="form-control" value="<?php echo $testimonial['testimonial_name']; ?>" required> </div> <div class="mb-3"> <label for="testimonial_designation" class="form-label">Testimonial Designation</label> <input type="text" name="testimonial_designation" id="testimonial_designation" class="form-control" value="<?php echo $testimonial['testimonial_designation']; ?>" required> </div> <div class="mb-3"> <label for="testimonial_comment" class="form-label">Testimonial Comment</label> <textarea name="testimonial_comment" id="testimonial_comment" class="form-control" rows="4" required><?php echo $testimonial['testimonial_comment']; ?></textarea> </div> </div> <div class="col-md-6"> <div class="mb-3"> <label for="testimonial_image" class="form-label">Testimonial Image</label> <input type="file" name="testimonial_image" id="testimonial_image" class="form-control"> <?php if ($testimonial['testimonial_image']) { ?> <div class="mt-2"> <img src="uploads/testimonials/<?php echo $testimonial['testimonial_image']; ?>" alt="Testimonial Image" width="100"> </div> <?php } ?> </div> </div> </div> <button type="submit" class="btn btn-primary">Update Testimonial</button> </form> </div> </div> </div> </div> </div> <?php require('footer.php'); ?> </body> </html>