D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home3
/
encodto1
/
tresboutique.in
/
tresadmin
/
Filename :
add_category.php
back
Copy
<?php include 'config.php'; if (!isset($_SESSION['admin_name'])) { echo '<script>window.location.href = "login.php";</script>'; exit; } if ($_SERVER['REQUEST_METHOD'] === 'POST') { $categoryName = mysqli_real_escape_string($conn, $_POST['product_category_name']); $categoryStatus = mysqli_real_escape_string($conn, $_POST['product_category_status']); // Handle file upload $targetDir = "uploads/"; $imageFileName = basename($_FILES["product_category_image"]["name"]); $targetFilePath = $targetDir . $imageFileName; $uploadOk = true; if (!empty($imageFileName)) { $imageFileType = strtolower(pathinfo($targetFilePath, PATHINFO_EXTENSION)); $allowedFileTypes = ['jpg', 'jpeg', 'png', 'gif']; if (in_array($imageFileType, $allowedFileTypes)) { if (move_uploaded_file($_FILES["product_category_image"]["tmp_name"], $targetFilePath)) { // Successfully uploaded } else { $uploadOk = false; $errorMessage = "Sorry, there was an error uploading the file."; } } else { $uploadOk = false; $errorMessage = "Invalid file type. Only JPG, JPEG, PNG, and GIF files are allowed."; } } if ($uploadOk) { $query = "INSERT INTO product_category (product_category_name, product_category_image, product_category_status) VALUES ('$categoryName', '$imageFileName', '$categoryStatus')"; if (mysqli_query($conn, $query)) { echo '<script>alert("Category added successfully."); window.location.href = "categories.php";</script>'; } else { echo '<script>alert("Error adding category: ' . mysqli_error($conn) . '");</script>'; } } else { echo '<script>alert("' . $errorMessage . '");</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"> <!-- Page Sidebar Start --> <?php require('sidebar.php'); ?> <!-- Page Sidebar End --> <div class="page-body"> <div class="container-fluid"> <div class="page-title"> <h3>Add Category</h3> </div> </div> <div class="container-fluid"> <div class="row"> <div class="col-md-8 offset-md-2"> <div class="card"> <div class="card-header"> <h5>Category Details</h5> </div> <div class="card-body"> <form action="" method="POST" enctype="multipart/form-data"> <div class="mb-3"> <label for="product_category_name" class="form-label">Category Name</label> <input type="text" class="form-control" id="product_category_name" name="product_category_name" required> </div> <div class="mb-3"> <label for="product_category_image" class="form-label">Category Image</label> <input type="file" class="form-control" id="product_category_image" name="product_category_image" required> </div> <div class="mb-3"> <label for="product_category_status" class="form-label">Category Status</label> <select class="form-control" id="product_category_status" name="product_category_status" required> <option value="Active">Active</option> <option value="Inactive">Inactive</option> </select> </div> <button type="submit" class="btn btn-primary">Add Category</button> </form> </div> </div> </div> </div> </div> </div> </div> </div> <?php require('footer.php'); ?> </body> </html>