D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home3
/
encodto1
/
tresboutique.in
/
tresadmin
/
Filename :
add_testimonial.php
back
Copy
<?php include 'config.php'; if ($_SERVER['REQUEST_METHOD'] === 'POST') { // Collect and sanitize form data $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 = date('Y-m-d H:i:s'); // Handle image upload $testimonial_image = null; if (!empty($_FILES['testimonial_image']['name'])) { $targetDir = "uploads/testimonials/"; $fileName = basename($_FILES['testimonial_image']['name']); $targetFilePath = $targetDir . $fileName; // Check if the file is an image $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 { // Move uploaded file if (move_uploaded_file($_FILES['testimonial_image']['tmp_name'], $targetFilePath)) { $testimonial_image = $fileName; } else { echo '<script>alert("Error uploading image.");</script>'; } } } // Insert data into the database $query = "INSERT INTO testimonial (testimonial_name, testimonial_image, testimonial_designation, testimonial_comment, created_at) VALUES ('$testimonial_name', '$testimonial_image', '$testimonial_designation', '$testimonial_comment', '$created_at')"; if (mysqli_query($conn, $query)) { echo '<script>alert("Testimonial added successfully."); window.location.href = "testimonials.php";</script>'; } else { echo '<script>alert("Error adding 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>Add 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" 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" 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></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"> </div> </div> </div> <button type="submit" class="btn btn-primary">Add Testimonial</button> </form> </div> </div> </div> </div> </div> <?php require('footer.php'); ?> </body> </html>