File manager - Edit - /var/www/order.cmtc.ac.th/admin/products_1.php
Back
<?php session_start(); if(!isset($_SESSION['admin'])) { header('Location: index.php'); exit; } include('../config/db.php'); // ✅ เพิ่มสินค้าใหม่ if(isset($_POST['add'])) { $name = $conn->real_escape_string($_POST['name']); $price = floatval($_POST['price']); $stock = intval($_POST['stock']); $img1 = ""; $img2 = ""; if(!empty($_FILES['img1']['name'])) { $img1 = time().'_1_'.$_FILES['img1']['name']; move_uploaded_file($_FILES['img1']['tmp_name'], "../uploads/products/".$img1); } if(!empty($_FILES['img2']['name'])) { $img2 = time().'_2_'.$_FILES['img2']['name']; move_uploaded_file($_FILES['img2']['tmp_name'], "../uploads/products/".$img2); } $conn->query("INSERT INTO products(name, price, stock, img1, img2) VALUES('$name', $price, $stock, '$img1', '$img2')"); header("Location: products.php?added=1"); exit; } // ✅ ลบสินค้า if(isset($_GET['delete'])) { $id = intval($_GET['delete']); $conn->query("DELETE FROM products WHERE id=$id"); header("Location: products.php?deleted=1"); exit; } // ✅ ดึงข้อมูลสินค้า $res = $conn->query("SELECT * FROM products ORDER BY id DESC"); ?> <!DOCTYPE html> <html lang="th"> <head> <meta charset="UTF-8"> <title>จัดการรายการพระ</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"> <link href="https://fonts.googleapis.com/css2?family=Kanit:wght@300;400;500;600&display=swap" rel="stylesheet"> <style> body, * { font-family: 'Kanit', sans-serif !important; } img.thumb { width: 100px; border-radius: 8px; box-shadow: 0 0 5px rgba(0,0,0,0.1); } </style> </head> <body class="bg-light"> <?php include("menu.php"); ?> <div class="container py-4"> <h3 class="mb-3">📿 จัดการรายการพระ</h3> <?php if(isset($_GET['added'])): ?> <div class="alert alert-success">✅ เพิ่มรายการพระเรียบร้อยแล้ว!</div> <?php elseif(isset($_GET['deleted'])): ?> <div class="alert alert-danger">🗑️ ลบรายการพระเรียบร้อยแล้ว!</div> <?php endif; ?> <!-- ฟอร์มเพิ่มรายการพระ --> <div class="card mb-4"> <div class="card-header bg-primary text-white fw-bold">➕ เพิ่มรายการพระใหม่</div> <div class="card-body"> <form method="post" enctype="multipart/form-data"> <div class="row g-3"> <div class="col-md-4"> <label class="form-label">ชื่อพระ</label> <input type="text" name="name" class="form-control" required> </div> <div class="col-md-3"> <label class="form-label">ราคา (บาท)</label> <input type="number" name="price" step="0.01" class="form-control" required> </div> <div class="col-md-2"> <label class="form-label">จำนวนคงเหลือ</label> <input type="number" name="stock" class="form-control" required> </div> <div class="col-md-3"> <label class="form-label">รูปด้านหน้า</label> <input type="file" name="img1" class="form-control"> </div> <div class="col-md-3"> <label class="form-label">รูปด้านหลัง</label> <input type="file" name="img2" class="form-control"> </div> <div class="col-12 text-end mt-3"> <button type="submit" name="add" class="btn btn-success">บันทึก</button> </div> </div> </form> </div> </div> <!-- ตารางแสดงรายการพระ --> <div class="card"> <div class="card-header bg-dark text-white fw-bold">📋 รายการพระทั้งหมด</div> <div class="card-body"> <table class="table table-bordered align-middle"> <thead class="table-light"> <tr> <th width="5%">ID</th> <th>ชื่อพระ</th> <th>ราคา</th> <th>คงเหลือ</th> <th>รูปด้านหน้า</th> <th>รูปด้านหลัง</th> <th width="10%">จัดการ</th> </tr> </thead> <tbody> <?php if($res->num_rows > 0): ?> <?php while($row = $res->fetch_assoc()): ?> <tr> <td><?=$row['id']?></td> <td><?=$row['name']?></td> <td><?=number_format($row['price'],2)?></td> <td><?=$row['stock']?></td> <td> <?php if($row['img1']): ?> <img src="../uploads/products/<?=$row['img1']?>" class="thumb"> <?php endif; ?> </td> <td> <?php if($row['img2']): ?> <img src="../uploads/products/<?=$row['img2']?>" class="thumb"> <?php endif; ?> </td> <td> <a href="?delete=<?=$row['id']?>" onclick="return confirm('แน่ใจหรือไม่ว่าต้องการลบรายการนี้?');" class="btn btn-danger btn-sm">ลบ</a> </td> </tr> <?php endwhile; ?> <?php else: ?> <tr><td colspan="7" class="text-center text-muted">ยังไม่มีรายการพระ</td></tr> <?php endif; ?> </tbody> </table> </div> </div> </div> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script> </body> </html>
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.43 |
proxy
|
phpinfo
|
Settings