:: **Zploit** v1.0 | Current Path: **/home/kreativepixelz/www/demo/jdc_studio/admin/**
:: Editing File: sub_subcategory_save.php
<?php include_once("session.php"); include("db.php"); $upload_dir = '../uploads/sub_subcategory/'; if (!is_dir($upload_dir)) { mkdir($upload_dir, 0777, true); } if ($_SERVER["REQUEST_METHOD"] == "POST") { $category_id = (int)($_POST['category_id'] ?? 0); $subcategory_id = (int)($_POST['subcategory_id'] ?? 0); $name = trim($_POST['name'] ?? ''); $subheading = trim($_POST['subheading'] ?? ''); $content = trim($_POST['content'] ?? ''); $url = trim($_POST['url'] ?? ''); $sort_order = (int)($_POST['sort_order'] ?? 0); $image_path = NULL; if (empty($category_id) || empty($subcategory_id) || empty($name)) { $_SESSION['error'] = "Category, Subcategory and Name are required."; header("Location: sub_subcategory_add.php"); exit; } // Image Upload if (!empty($_FILES['image']['name']) && $_FILES['image']['error'] === UPLOAD_ERR_OK) { $file_ext = strtolower(pathinfo($_FILES['image']['name'], PATHINFO_EXTENSION)); $allowed_ext = ['jpg', 'jpeg', 'png', 'gif']; if (in_array($file_ext, $allowed_ext)) { $new_file_name = uniqid('subsubcat_') . '.' . $file_ext; $destination = $upload_dir . $new_file_name; if (move_uploaded_file($_FILES['image']['tmp_name'], $destination)) { $image_path = $new_file_name; } else { $_SESSION['error'] = "Failed to upload image."; header("Location: sub_subcategory_add.php"); exit; } } else { $_SESSION['error'] = "Invalid image type. Only JPG, PNG, GIF allowed."; header("Location: sub_subcategory_add.php"); exit; } } // Insert Query $sql = "INSERT INTO sub_subcategories (category_id, subcategory_id, image, name, content, url, sort_order, subheading) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"; $stmt = mysqli_prepare($conn, $sql); mysqli_stmt_bind_param($stmt, "iissssis", $category_id, $subcategory_id, $image_path, $name, $content, $url, $sort_order, $subheading ); if (mysqli_stmt_execute($stmt)) { $_SESSION['success'] = "Sub Sub Category '{$name}' added successfully!"; header("Location: sub_subcategory_list.php"); exit; } else { $_SESSION['error'] = "Database error: " . mysqli_error($conn); if ($image_path && file_exists($upload_dir . $image_path)) { unlink($upload_dir . $image_path); } header("Location: sub_subcategory_add.php"); exit; } mysqli_stmt_close($stmt); mysqli_close($conn); } else { $_SESSION['error'] = "Invalid request method."; header("Location: sub_subcategory_add.php"); exit; } ?>