diff --git a/controllers/tourController.js b/controllers/tourController.js index 37c73d361210f46b970341a09de6f6093cd7dfc1..0e025d111dff402542da3134a26d227e8064d405 100644 --- a/controllers/tourController.js +++ b/controllers/tourController.js @@ -310,12 +310,15 @@ exports.createBooking = async (req, res) => { return res.status(404).send('Tour not found.'); } - // ทำการจองทัวร์ - await Booking.createBooking(userId, tourId); - res.redirect('/my-bookings'); // หลังจากจองเสร็จ เปลี่ยนเส้นทางไปยังหน้าการจองของผู้ใช้ + // ทำการจองทัวร์ (บันทึกการจองในตาราง bookings) + const bookingQuery = 'INSERT INTO bookings (user_id, tour_id) VALUES (?, ?)'; + await pool.execute(bookingQuery, [userId, tourId]); + + // หลังจากบันทึกการจองสำเร็จแล้ว, ส่งผู้ใช้กลับไปที่หน้ารายการจอง + res.redirect('/my-bookings'); } catch (error) { console.error('Error creating booking:', error.message); - res.status(500).send('Internal Server Error'); + res.status(500).send('เกิดข้อผิดพลาดในการจองทัวร์'); } };