Editing: products.php
Kembali
<?php include '../components/connect.php'; session_start(); $admin_id = $_SESSION['admin_id']; if(!isset($admin_id)){ header('location:admin_login.php'); }; if(isset($_POST['add_product'])){ $name = $_POST['name']; $name = filter_var($name, FILTER_SANITIZE_STRING); // $price = $_POST['price']; // $price = filter_var($price, FILTER_SANITIZE_STRING); $details = $_POST['details']; $details = filter_var($details, FILTER_SANITIZE_STRING); $category = $_POST['category']; $category = filter_var($category, FILTER_SANITIZE_STRING); $hs_code = $_POST['hs_code']; $hs_code = filter_var($hs_code, FILTER_SANITIZE_STRING); $image_01 = $_FILES['image_01']['name']; $image_01 = filter_var($image_01, FILTER_SANITIZE_STRING); $image_size_01 = $_FILES['image_01']['size']; $image_tmp_name_01 = $_FILES['image_01']['tmp_name']; $image_folder_01 = '../uploaded_img/'.$image_01; $image_02 = $_FILES['image_02']['name']; $image_02 = filter_var($image_02, FILTER_SANITIZE_STRING); $image_size_02 = $_FILES['image_02']['size']; $image_tmp_name_02 = $_FILES['image_02']['tmp_name']; $image_folder_02 = '../uploaded_img/'.$image_02; $image_03 = $_FILES['image_03']['name']; $image_03 = filter_var($image_03, FILTER_SANITIZE_STRING); $image_size_03 = $_FILES['image_03']['size']; $image_tmp_name_03 = $_FILES['image_03']['tmp_name']; $image_folder_03 = '../uploaded_img/'.$image_03; $select_products =mysqli_query($conn,"SELECT * FROM products WHERE name = '$name';"); // $select_products->execute([$name]); if(mysqli_num_rows($select_products)> 0){ $message[] = 'product name already exist!'; }else{ $insert_products = mysqli_query($conn,"INSERT INTO `products`(name, details, image_01, image_02, image_03,category,hs_code) VALUES('$name','$details','$image_01','$image_02','$image_03','$category','$hs_code')"); // $insert_products->execute([$name, $details, $price, $image_01, $image_02, $image_03]); echo(mysqli_error($conn)); if($insert_products){ if($image_size_01 > 2000000 OR $image_size_02 > 2000000 OR $image_size_03 > 2000000){ $message[] = 'image size is too large!'; }else{ move_uploaded_file($image_tmp_name_01, $image_folder_01); move_uploaded_file($image_tmp_name_02, $image_folder_02); move_uploaded_file($image_tmp_name_03, $image_folder_03); $message[] = 'new product added!'; } } } }; ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>products</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css"> <link rel="stylesheet" href="../css/admin_style.css"> </head> <body> <?php include '../components/admin_header.php'; ?> <section class="add-products"> <h1 class="heading">add product</h1> <form action="" method="post" enctype="multipart/form-data"> <div class="flex"> <div class="inputBox"> <span>Product Name (required)</span> <input type="text" class="box" required maxlength="100" placeholder="Enter product name" name="name"> </div> <!--<div class="inputBox">--> <!-- <span>Product Price (required)</span>--> <!-- <input type="number" min="0" class="box" required max="9999999999" placeholder="Enter product price" onkeypress="if(this.value.length == 10) return false;" name="price">--> <!--</div>--> <div class="inputBox"> <span>Image 01 (required)</span> <input type="file" name="image_01" accept="image/jpg, image/jpeg, image/png, image/webp" class="box" required> </div> <div class="inputBox"> <span>Image 02 (required)</span> <input type="file" name="image_02" accept="image/jpg, image/jpeg, image/png, image/webp" class="box" required> </div> <div class="inputBox"> <span>Image 03 (required)</span> <input type="file" name="image_03" accept="image/jpg, image/jpeg, image/png, image/webp" class="box" required> </div> <div class="inputBox"> <span>Product details (required)</span> <textarea name="details" placeholder="Enter product details" class="box" required maxlength="500" cols="30" rows="10"></textarea> </div> <div class="inputBox"> <span>Category (required)</span> <select name="category" placeholder="enter category" class="box"> <?php $categories=mysqli_query($conn,"SELECT category FROM categories"); print_r($categories); if(mysqli_num_rows($categories)>0){ while($categoryArray=mysqli_fetch_array($categories)){ print_r($categoryArray); echo('<option value="'.$categoryArray[0].'">'.$categoryArray[0].'</option>'); } } ?> <!-- <option value="">Gobhi</option> <option value="">Palak</option> <option value="">Kadi pAtta</option> <option value="">Soha</option> --> </select> </div> <!-- <div class="inputBox"> </div> --> <div class="inputBox"> <span>HS Code (required)</span> <input type="text" class="box" required maxlength="100" placeholder="Enter HS Code" name="hs_code"> </div> <input type="submit" value="add product" class="btn" name="add_product"> </form> </section> <!-- <section class="show-products"> <h1 class="heading">products added</h1> <div class="box-container"> <?php $select_products = mysqli_query($conn,"SELECT * FROM `products`"); if(mysqli_num_rows($select_products) > 0){ while($fetch_products = mysqli_fetch_assoc($select_products)){ ?> <div class="box"> <img src="../uploaded_img/<?= $fetch_products['image_01']; ?>" alt=""> <div class="name"><?= $fetch_products['name']; ?></div> <div class="price">₹<span><?= $fetch_products['price']; ?></span>/-</div> <div class="details"><span><?= $fetch_products['details']; ?></span></div> <div class="flex-btn"> <a href="update_product.php?update=<?= $fetch_products['id']; ?>" class="option-btn">update</a> <a href="products.php?delete=<?= $fetch_products['id']; ?>" class="delete-btn" onclick="return confirm('delete this product?');">delete</a> </div> </div> <?php } }else{ echo '<p class="empty">no products added yet!</p>'; } ?> </div> </section> --> <script src="../js/admin_script.js"></script> </body> </html>
SIMPAN PERUBAHAN