From bf00757f7f9237e0c2f6d4aab4bc2ca2fe91afe1 Mon Sep 17 00:00:00 2001
From: 65160270 <65160270@go.buu.ac.th>
Date: Fri, 28 Mar 2025 20:41:28 +0700
Subject: [PATCH] update-cart

---
 shop-routes/product.js | 13 +++----------
 views/product.ejs      |  1 -
 2 files changed, 3 insertions(+), 11 deletions(-)

diff --git a/shop-routes/product.js b/shop-routes/product.js
index f19cdb3..b9041d8 100644
--- a/shop-routes/product.js
+++ b/shop-routes/product.js
@@ -41,24 +41,17 @@ router.get("/add", (req, res) => {
 });
 
 // เพิ่มสินค้าใหม่พร้อมรูป
-router.post("/add", upload.single("image"), async (req, res) => {
+router.post("/add", upload.single("image"), async (req, res) => { // เปลี่ยนจาก "images" เป็น "image" ให้ตรงกับ name ของ input file
     console.log("req.file:", req.file); // ตรวจสอบว่า multer ได้รับไฟล์หรือไม่
-    console.log("req.body:", req.body); // ตรวจสอบค่าที่ส่งมาจากฟอร์ม
 
     try {
-        const { name, price, stock, description } = req.body;
-
-        // ถ้าไม่มีไฟล์ที่อัปโหลด
-        if (!req.file) {
-            console.error("No file uploaded.");
-            return res.status(400).send("No file uploaded.");
-        }
+        const { name, price, stock, description } = req.body; // เพิ่ม description
 
         const imagePath = "/uploads/" + req.file.filename;
 
         await pool.execute(
             "INSERT INTO products (name, price, stock, description, image_url) VALUES (?, ?, ?, ?, ?)",
-            [name, price, stock, description, imagePath]
+            [name, price, stock, description, imagePath] // เพิ่ม description
         );
 
         res.redirect("/products");
diff --git a/views/product.ejs b/views/product.ejs
index c9b1754..f0d89b1 100644
--- a/views/product.ejs
+++ b/views/product.ejs
@@ -14,7 +14,6 @@
             <th>ราคา</th>
             <th>จำนวน</th>
             <th>คำบรรยาย</th>
-            <th>จัดการ</th>
         </tr>
         <% products.forEach(product => { %>
             <tr>
-- 
GitLab