/
/
home
/
u523034047
/
domains
/
nainitalfloweritech.com
/
public_html
/
admin
Server: in-mum-web1112.main-hosting.eu (62.72.28.111)
You: 216.73.216.89
PHP 8.3.16
Dir:
/home/u523034047/domains/nainitalfloweritech.com/public_html/admin
Edit:
/home/u523034047/domains/nainitalfloweritech.com/public_html/admin/edit-products.php
<?php session_start(); include('include/config.php'); include('include/admin-menu.php'); if (empty($_SESSION['alogin'])) { header('Location: index.php'); exit(); } $pid = intval($_GET['id']); date_default_timezone_set('Asia/Kolkata'); /* ===== UPDATE PRODUCT ===== */ if (isset($_POST['submit'])) { $stmt = $con->prepare(" UPDATE products SET category=?, subCategory=?, productName=?, productCompany=?, productPrice=?, productPriceBeforeDiscount=?, productDescription=?, shippingCharge=?, productAvailability=? WHERE id=? "); $stmt->bind_param( "iissddsssi", $_POST['category'], $_POST['subcategory'], $_POST['productName'], $_POST['productCompany'], $_POST['productprice'], $_POST['productpricebd'], $_POST['productDescription'], $_POST['productShippingcharge'], $_POST['productAvailability'], $pid ); if ($stmt->execute()) { $_SESSION['msg'] = "Product updated successfully!"; } else { $_SESSION['msg'] = "Update failed!"; } header("Location: edit-products.php?id=".$pid); exit(); } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Edit Product | Admin</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <script src="https://cdn.ckeditor.com/ckeditor5/39.0.1/classic/ckeditor.js"></script> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet"> <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" rel="stylesheet"> <style> body{ background:linear-gradient(135deg,#667eea,#764ba2); min-height:100vh; font-family:'Segoe UI',sans-serif; } .card-box{ background:#fff; border-radius:12px; box-shadow:0 15px 40px rgba(0,0,0,.2); padding:25px; } .form-control, .form-select{ height:45px; } .section-title{ font-weight:600; margin-bottom:15px; } </style> </head> <body> <div class="container py-5"> <div class="card-box"> <h4 class="section-title"> <i class="fa fa-pen"></i> Edit Product </h4> <?php if(!empty($_SESSION['msg'])){ ?> <div class="alert alert-success text-center"> <?php echo $_SESSION['msg']; $_SESSION['msg']=""; ?> </div> <?php } ?> <?php $q = $con->prepare(" SELECT p.*, c.categoryName, c.id cid, s.subcategory, s.id sid FROM products p JOIN category c ON c.id=p.category JOIN subcategory s ON s.id=p.subCategory WHERE p.id=? "); $q->bind_param("i",$pid); $q->execute(); $row = $q->get_result()->fetch_assoc(); ?> <form method="post"> <div class="row g-3"> <div class="col-md-6"> <label>Category</label> <select name="category" class="form-select" onchange="getSubcat(this.value)" required> <option value="<?php echo $row['cid']; ?>"><?php echo $row['categoryName']; ?></option> <?php $cat=$con->query("SELECT * FROM category"); while($c=$cat->fetch_assoc()){ if($c['id']!=$row['cid']) echo "<option value='{$c['id']}'>{$c['categoryName']}</option>"; } ?> </select> </div> <div class="col-md-6"> <label>Sub Category</label> <select name="subcategory" id="subcategory" class="form-select" required> <option value="<?php echo $row['sid']; ?>"><?php echo $row['subcategory']; ?></option> </select> </div> <div class="col-md-6"> <label>Product Name</label> <input type="text" name="productName" class="form-control" value="<?php echo $row['productName']; ?>" required> </div> <div class="col-md-6"> <label>Company</label> <input type="text" name="productCompany" class="form-control" value="<?php echo $row['productCompany']; ?>" required> </div> <div class="col-md-6"> <label>Price Before Discount</label> <input type="number" step="0.01" name="productpricebd" class="form-control" value="<?php echo $row['productPriceBeforeDiscount']; ?>"> </div> <div class="col-md-6"> <label>Price</label> <input type="number" step="0.01" name="productprice" class="form-control" value="<?php echo $row['productPrice']; ?>"> </div> <div class="col-md-12"> <label>Description</label> <textarea name="productDescription" id="editor"><?php echo $row['productDescription']; ?></textarea> </div> <div class="col-md-6"> <label>Shipping Charge</label> <input type="number" name="productShippingcharge" class="form-control" value="<?php echo $row['shippingCharge']; ?>"> </div> <div class="col-md-6"> <label>Availability</label> <select name="productAvailability" class="form-select"> <option><?php echo $row['productAvailability']; ?></option> <option>In Stock</option> <option>Out of Stock</option> </select> </div> </div> <hr> <div class="row text-center"> <div class="col-md-4"> <img src="productimages/<?php echo $pid; ?>/<?php echo $row['productImage1']; ?>" class="img-fluid rounded mb-2"> <br><a href="update-image1.php?id=<?php echo $pid; ?>">Change</a> </div> <div class="col-md-4"> <img src="productimages/<?php echo $pid; ?>/<?php echo $row['productImage2']; ?>" class="img-fluid rounded mb-2"> <br><a href="update-image2.php?id=<?php echo $pid; ?>">Change</a> </div> <div class="col-md-4"> <img src="productimages/<?php echo $pid; ?>/<?php echo $row['productImage3']; ?>" class="img-fluid rounded mb-2"> <br><a href="update-image3.php?id=<?php echo $pid; ?>">Change</a> </div> </div> <hr> <button type="submit" name="submit" class="btn btn-primary w-100"> <i class="fa fa-save"></i> Update Product </button> </form> </div> </div> <script src="https://code.jquery.com/jquery-3.7.1.min.js"></script> <script> function getSubcat(val){ $.post("get_subcat.php",{cat_id:val},function(data){ $("#subcategory").html(data); }); } </script> <script> document.addEventListener("DOMContentLoaded", function() { ClassicEditor .create(document.querySelector('#editor'), { toolbar: [ 'heading', '|', 'bold', 'italic', 'link', 'bulletedList', 'numberedList', '|', 'undo', 'redo' ] }) .catch(error => { console.error(error); }); }); </script> </body> </html>
Ukuran: 6.3 KB