:: **Zploit** v1.0 | Current Path: **/home/kreativepixelz/www/demo/jdc/new/admin/**
:: Editing File: product_edit.php
<?php require_once 'db.php'; require_once 'session.php'; include "header.php"; /* 1️⃣ Check ID */ if (!isset($_GET['id']) || empty($_GET['id'])) { $_SESSION['error'] = "Error: Product ID missing."; header("Location: product.php"); exit; } $product_id = (int)$_GET['id']; /* 2️⃣ Fetch Product */ $sql = "SELECT * FROM products WHERE id = ?"; $stmt = mysqli_prepare($conn,$sql); mysqli_stmt_bind_param($stmt,"i",$product_id); mysqli_stmt_execute($stmt); $result = mysqli_stmt_get_result($stmt); $product = mysqli_fetch_assoc($result); mysqli_stmt_close($stmt); if(!$product){ $_SESSION['error']="Product not found"; header("Location: product.php"); exit; } /* 3️⃣ Fetch Categories */ $categories = []; $res = mysqli_query($conn,"SELECT id,name FROM categories ORDER BY name ASC"); while($row=mysqli_fetch_assoc($res)){ $categories[]=$row; } /* 4️⃣ Fetch Subcategories */ $subcategories = []; $res = mysqli_query($conn,"SELECT id,name FROM subcategories WHERE category_id=".$product['category_id']); while($row=mysqli_fetch_assoc($res)){ $subcategories[]=$row; } /* 5️⃣ Fetch Sub Subcategories */ $subsub = []; $res = mysqli_query($conn,"SELECT id,name FROM sub_subcategories WHERE subcategory_id=".$product['subcategory_id']); while($row=mysqli_fetch_assoc($res)){ $subsub[]=$row; } ?> <div class="page-content-wrapper"> <div class="page-content"> <div class="page-breadcrumb d-none d-sm-flex align-items-center mb-3"> <div class="breadcrumb-title pe-3">Products</div> </div> <div class="card"> <div class="card-header"> <h6>Edit Product - <?= htmlspecialchars($product['name']) ?></h6> </div> <div class="card-body"> <form action="product_update.php" method="POST" enctype="multipart/form-data"> <input type="hidden" name="product_id" value="<?= $product['id'] ?>"> <input type="hidden" name="old_image" value="<?= $product['image'] ?>"> <div class="row"> <!-- Category --> <div class="col-sm-4 mb-3"> <label>Category</label> <select class="form-control" name="category_id" required> <option value="">Select</option> <?php foreach($categories as $cat): ?> <option value="<?= $cat['id'] ?>" <?= ($product['category_id']==$cat['id'])?'selected':'' ?>> <?= htmlspecialchars($cat['name']) ?> </option> <?php endforeach; ?> </select> </div> <!-- Subcategory --> <div class="col-sm-4 mb-3"> <label>Subcategory</label> <select class="form-control" name="subcategory_id"> <option value="">Select</option> <?php foreach($subcategories as $sub): ?> <option value="<?= $sub['id'] ?>" <?= ($product['subcategory_id']==$sub['id'])?'selected':'' ?>> <?= htmlspecialchars($sub['name']) ?> </option> <?php endforeach; ?> </select> </div> <!-- SubSubCategory --> <div class="col-sm-4 mb-3"> <label>Sub Sub Category</label> <select class="form-control" name="sub_subcategory_id"> <option value="">Select</option> <?php foreach($subsub as $ss): ?> <option value="<?= $ss['id'] ?>" <?= ($product['sub_subcategory_id']==$ss['id'])?'selected':'' ?>> <?= htmlspecialchars($ss['name']) ?> </option> <?php endforeach; ?> </select> </div> <!-- Product Name --> <div class="col-sm-6 mb-3"> <label>Product Name</label> <input type="text" class="form-control" name="name" value="<?= htmlspecialchars($product['name']) ?>" required> </div> <!-- URL --> <div class="col-sm-6 mb-3"> <label>URL</label> <input type="text" class="form-control" name="url" value="<?= htmlspecialchars($product['url']) ?>"> </div> <!-- Image --> <div class="col-sm-4 mb-3"> <label>Image</label> <input type="file" class="form-control" name="image"> <?php if(!empty($product['image'])): ?> <br> <img src="../uploads/products/<?= $product['image'] ?>" width="60"> <?php endif; ?> </div> <!-- Actual Price --> <div class="col-sm-4 mb-3"> <label>Actual Price</label> <input type="text" class="form-control" name="actual_price" value="<?= $product['actual_price'] ?>"> </div> <!-- Old Price --> <div class="col-sm-4 mb-3"> <label>Old Price</label> <input type="text" class="form-control" name="old_price" value="<?= $product['old_price'] ?>"> </div> <!-- Color Name --> <div class="col-sm-4 mb-3"> <label>Color Name</label> <input type="text" class="form-control" name="color_name" value="<?= $product['color_name'] ?>"> </div> <!-- Color Code --> <div class="col-sm-4 mb-3"> <label>Color Code</label> <input type="color" class="form-control" name="color_code" value="<?= $product['color_code'] ?>"> </div> <!-- Size --> <div class="col-sm-4 mb-3"> <label>Size</label> <input type="text" class="form-control" name="size_name" value="<?= $product['size_name'] ?>"> </div> <!-- Description --> <div class="col-sm-12 mb-3"> <label>Description</label> <textarea class="form-control" name="description" rows="4"><?= htmlspecialchars($product['description']) ?></textarea> </div> <!-- Additional Info --> <div class="col-sm-12 mb-3"> <label>Additional Information</label> <textarea class="form-control" name="additional_information" rows="3"><?= htmlspecialchars($product['additional_information']) ?></textarea> </div> <!-- Shipping --> <div class="col-sm-12 mb-3"> <label>Shipping & Return</label> <textarea class="form-control" name="shipping_return" rows="3"><?= htmlspecialchars($product['shipping_return']) ?></textarea> </div> <div class="col-12 mt-4"> <button class="btn btn-success">Update Product</button> <a href="product.php" class="btn btn-warning">Back</a> </div> </div> </form> </div> </div> </div> </div> <?php include "footer.php"; ?>