diff --git a/models/tourModel.js b/models/tourModel.js index 0cd19859759f79cbbd39321ba68f1fea34a6ea15..b3b335a87d69f400f68cf018516d75a4adfacb70 100644 --- a/models/tourModel.js +++ b/models/tourModel.js @@ -53,19 +53,19 @@ class Tour { // อัปเดตทัวร์ static async updateTour(tourId, tourData) { - const { name, description, price, duration } = tourData; + const { name, description, price, duration, companyid } = tourData; // ตรวจสอบข้อมูลให้ครบถ้วน - if (!name || !description || !price || !duration) { + if (!name || !description || !price || !duration|| !companyid) { throw new Error('ข้อมูลไม่ครบถ้วน'); } // สร้างคำสั่ง SQL สำหรับการอัปเดตข้อมูล - const query = 'UPDATE tours SET name = ?, description = ?, price = ?, duration = ? WHERE id = ?'; + const query = 'UPDATE tours SET name = ?, description = ?, price = ?, duration = ? , companyid = ? WHERE id = ?'; try { // ใช้ tourId ที่รับมาในการอัปเดต - const [results] = await pool.execute(query, [name, description, price, duration, tourId]); + const [results] = await pool.execute(query, [name, description, price, duration, companyid, tourId]); console.log('✅ Update results:', results); return results; } catch (error) { diff --git a/views/edittour.ejs b/views/edittour.ejs index 9d8a864cec28fb2874101dfd76491e8cb951f9ea..53b344680555b1c1d6d60691f4d9fc43fb14a7a1 100644 --- a/views/edittour.ejs +++ b/views/edittour.ejs @@ -26,6 +26,15 @@ <label for="tourDuration">ระยะเวลา (วัน):</label> <input type="number" id="tourDuration" name="duration" value="<%= tour.duration %>" required> </div> + <div> + <label for="tourCompany">บริษัท:</label> + <select id="tourCompany" name="companyid" required> + <option value="" disabled selected>เลือกบริษัท</option> + <option value="1">Amazing Travel</option> + <option value="2">Wonderful Tours</option> + <option value="3">Explore Asia</option> + </select> + </div> <button type="submit">Update Tour</button> </form> </main>