D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home3
/
encodto1
/
universalhomedecor.in
/
admin
/
Filename :
edit_testimonial.php
back
Copy
<?php session_start(); require('config.php'); require('style.php'); // Check if admin is logged in if (!isset($_SESSION['admin_name'])) { echo '<script> window.location.href = "login.php";</script>'; exit; } // Function to get the current page name function getCurrentPage() { return basename($_SERVER['PHP_SELF']); } // Variable to hold the current page name $current_page = getCurrentPage(); $page_name = pathinfo($current_page, PATHINFO_FILENAME); // Check if testimonial ID is provided in the URL if (!isset($_GET['id']) || !is_numeric($_GET['id'])) { echo "Testimonial ID is missing or invalid!"; exit; } $id = intval($_GET['id']); $query = "SELECT * FROM `testimonials` WHERE `id`=$id"; $result = mysqli_query($conn, $query); if (!$result || mysqli_num_rows($result) === 0) { echo "Testimonial not found!"; exit; } $item = mysqli_fetch_assoc($result); $imageSrc = htmlspecialchars($item['image'], ENT_QUOTES, 'UTF-8'); // Check if form is submitted if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['edit_testimonials'])) { // Validate and sanitize form inputs $name = mysqli_real_escape_string($conn, $_POST['name']); $review = mysqli_real_escape_string($conn, $_POST['review']); $designation = mysqli_real_escape_string($conn, $_POST['designation']); // Handle image upload if ($_FILES['image']['name']) { $imgpath = image_upload($_FILES['image']); // Check if image upload failed if (strpos($imgpath, "Sorry") !== false) { // Redirect with error message header("Location: index.php?alert=img_upload_failed&message=" . urlencode($imgpath)); exit; } } else { // Retain existing image path if no new image is uploaded $imgpath = $item['image']; } // Update testimonial details $query = "UPDATE `testimonials` SET `name`='$name', `designation`='$designation', `review`='$review', `image`='$imgpath' WHERE `id`=$id"; if (mysqli_query($conn, $query)) { header("Location: testimonials.php"); exit; } else { echo "Error updating testimonial: " . mysqli_error($conn); exit; } } ?> <!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 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="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>?id=<?php echo $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"> <div class="row"> <div class="col"> <div class="mb-3"> <label>Testimonial Name</label> <input type="text" name="name" id="name" class="form-control" value="<?php echo $item['name']; ?>"> </div> </div> </div> <div class="row"> <div class="col"> <div class="mb-3"> <label>Designation</label> <input type="text" name="designation" id="designation" class="form-control" value="<?php echo $item['designation']; ?>"> </div> </div> </div> <div class="row"> <div class="col"> <div class="mb-3"> <textarea name="review" placeholder="Enter review" id="review" class="form-control" rows="6"><?php echo $item['review']; ?></textarea> </div> </div> </div> <div class="row"> <div class="col"> <div class="mb-3"> <label>Upload Image</label> <input type="file" name="image" placeholder="Upload Image" class="form-control" accept=".jpg, .jpeg, .png, .svg"> </div> </div> </div> </div> </div> <div class="row"> <div class="modal-footer"> <button type="submit" class="btn btn-success" name="edit_testimonial">Update Testimonial</button> <button type="reset" class="btn btn-outline-secondary" data-bs-dismiss="modal">Cancel</button> </div> </div> </div> </div> </div> </div> </form> <!-- Container-fluid Ends--> </div> <!-- latest jquery--> <?php include('footer.php') ?> </div> </div> </body> </html>