I'm working on a scheduling system were students would be able to book lessons with teachers in php and mysql.
There are 3 separate tables to hold the data and each has their own unique ids studentID, lessonID and teacherID. They are all Many to Many relationships. Many students can have many lessons. Many teachers can have many lessons. As such, there are two junction tables linking the students and teachers to the same lessons, Lessons/Students and Lessons/Teachers.
The problem I am running into is the I am making a form to input a new lesson. I want to be able to assign students and teachers in the same form. Most of the data in the form posts directly to the lessons table which is easy (start time, end time, room number, etc), but I'm running into trouble with the junction table.
I am pulling a list of the available students and teachers and intend to input them into the junction tables based on their IDs. I can't seem to figure out how I am supposed to go about capturing the lesson ID BEFORE it is actually created, as I need the lessonID for the junction table, but the lesson hasn't even been created yet.
All IDs auto increment. The only solution I can think of is to return the latest lessonID and increment by one. Is this a best practice? I get the feeling this might cause problems later. For example in situations when two users try to create lessons at the same time, or there is a delay and another lesson is created before another but they both post the same lesson ID to the junction table.
Any input is appreciated! Thanks