Gitlab@Informatics

Skip to content
Snippets Groups Projects
Commit bf00757f authored by 65160270's avatar 65160270
Browse files

update-cart

parent 99563091
No related branches found
No related tags found
No related merge requests found
...@@ -41,24 +41,17 @@ router.get("/add", (req, res) => { ...@@ -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.file:", req.file); // ตรวจสอบว่า multer ได้รับไฟล์หรือไม่
console.log("req.body:", req.body); // ตรวจสอบค่าที่ส่งมาจากฟอร์ม
try { try {
const { name, price, stock, description } = req.body; const { name, price, stock, description } = req.body; // เพิ่ม description
// ถ้าไม่มีไฟล์ที่อัปโหลด
if (!req.file) {
console.error("No file uploaded.");
return res.status(400).send("No file uploaded.");
}
const imagePath = "/uploads/" + req.file.filename; const imagePath = "/uploads/" + req.file.filename;
await pool.execute( await pool.execute(
"INSERT INTO products (name, price, stock, description, image_url) VALUES (?, ?, ?, ?, ?)", "INSERT INTO products (name, price, stock, description, image_url) VALUES (?, ?, ?, ?, ?)",
[name, price, stock, description, imagePath] [name, price, stock, description, imagePath] // เพิ่ม description
); );
res.redirect("/products"); res.redirect("/products");
......
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
<th>ราคา</th> <th>ราคา</th>
<th>จำนวน</th> <th>จำนวน</th>
<th>คำบรรยาย</th> <th>คำบรรยาย</th>
<th>จัดการ</th>
</tr> </tr>
<% products.forEach(product => { %> <% products.forEach(product => { %>
<tr> <tr>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment