D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home3
/
encodto1
/
tresboutique.in
/
tresadmin
/
Filename :
add_happyclient.php
back
Copy
<?php include 'config.php'; if ($_SERVER['REQUEST_METHOD'] === 'POST') { // Collect and sanitize form data $happyclient_name = mysqli_real_escape_string($conn, $_POST['happyclient_name']); $happyclient_desc = mysqli_real_escape_string($conn, $_POST['happyclient_desc']); // New field $created_at = date('Y-m-d H:i:s'); // Handle image upload $happyclient_image = null; if (!empty($_FILES['happyclient_image']['name'])) { $targetDir = "uploads/happyclients/"; $fileName = basename($_FILES['happyclient_image']['name']); $targetFilePath = $targetDir . $fileName; // Check if the file is an image $check = getimagesize($_FILES['happyclient_image']['tmp_name']); if ($check === false) { echo '<script>alert("File is not an image.");</script>'; } elseif ($_FILES['happyclient_image']['size'] > 5000000) { // 5MB limit echo '<script>alert("File is too large.");</script>'; } else { // Move uploaded file if (move_uploaded_file($_FILES['happyclient_image']['tmp_name'], $targetFilePath)) { $happyclient_image = $fileName; } else { echo '<script>alert("Error uploading image.");</script>'; } } } // Insert data into the database $query = "INSERT INTO happyclients (happyclient_name, happyclient_desc, happyclient_image, created_at) VALUES ('$happyclient_name', '$happyclient_desc', '$happyclient_image', '$created_at')"; if (mysqli_query($conn, $query)) { echo '<script>alert("Happy client added successfully."); window.location.href = "happyclients.php";</script>'; } else { echo '<script>alert("Error adding happy client: ' . 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 Happy Client</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="happyclient_name" class="form-label">Happy Client Name</label> <input type="text" name="happyclient_name" id="happyclient_name" class="form-control" required> </div> <div class="mb-3"> <label for="happyclient_desc" class="form-label">Happy Client Description</label> <textarea name="happyclient_desc" id="happyclient_desc" class="form-control" rows="4" required></textarea> </div> </div> <div class="col-md-6"> <div class="mb-3"> <label for="happyclient_image" class="form-label">Happy Client Image</label> <input type="file" name="happyclient_image" id="happyclient_image" class="form-control"> </div> </div> </div> <button type="submit" class="btn btn-primary">Add Happy Client</button> </form> </div> </div> </div> </div> </div> <?php require('footer.php'); ?> </body> </html>