diff --git a/shop-routes/product.js b/shop-routes/product.js index 5a7634b60dc79e8cd6204b353689da32dfd0020f..50870d0819ccf369348859a9ca83a7de90c8b0ce 100644 --- a/shop-routes/product.js +++ b/shop-routes/product.js @@ -53,7 +53,7 @@ router.post("/add", upload.single("image"), async (req, res) => { const imagePath = "/uploads/" + req.file.filename; // แก้จาก 'image' เป็น 'image_url' - await pool.execute("INSERT INTO products (name, price, stock, description, image_url) VALUES (?, ?, ?, ?)", + await pool.execute("INSERT INTO products (name, price, stock, image_url) VALUES (?, ?, ?, ?)", [name, price, stock, imagePath]); res.redirect("/products"); diff --git a/views/product.ejs b/views/product.ejs index 6defd4dcccfc456824c45deaf8e7afd8918a298f..f0d89b1fa9c4e22169fa0e5a56fd8ca6eb1f7563 100644 --- a/views/product.ejs +++ b/views/product.ejs @@ -6,7 +6,7 @@ </head> <body> <h2>รายการสินค้า</h2> - <a href="/products/add">Add</a> + <a href="/products/add">เพิ่มสินค้า</a> <table border="1"> <tr> <th>รูป</th> diff --git a/views/product_edit.ejs b/views/product_edit.ejs index ec6197a4c57e5165c5289c0b287f8fee093b8370..a54f07b40c43dd0a1a15f8baec91b8d429ecd5a3 100644 --- a/views/product_edit.ejs +++ b/views/product_edit.ejs @@ -2,37 +2,37 @@ <html lang="th"> <head> <meta charset="UTF-8"> - <title>Edit</title> + <title>แก้ไขสินค้า</title> </head> <body> - <h2>Edit</h2> + <h2>แก้ไขสินค้า</h2> <form action="/products/edit/<%= product.id %>" method="POST" enctype="multipart/form-data"> - <label>product_id:</label> + <label>รหัสสินค้า:</label> <input type="text" name="product_id" value="<%= product.id %>" readonly> <br> - <label>name:</label> + <label>ชื่อสินค้า:</label> <input type="text" name="name" value="<%= product.name %>" required> <br> - <label>price:</label> + <label>ราคา:</label> <input type="number" name="price" value="<%= product.price %>" required> <br> - <label>stock:</label> + <label>จำนวนสินค้า:</label> <input type="number" name="stock" value="<%= product.stock %>" required> <br> - <label>description:</label> + <label>คำบรรยายสินค้า:</label> <textarea name="description" required><%= product.description %></textarea> <br> - <label>image:</label> - <input type="file" name="image_url"> + <label>เปลี่ยนรูปภาพ (อัพโหลดใหม่ถ้าต้องการ):</label> + <input type="file" name="image"> <br> - <button type="submit">submit</button> + <button type="submit">บันทึกการแก้ไข</button> </form> </body> </html>