webdeveloper123 Posted February 26 Share Posted February 26 (edited) Hi Guys, I am creating a cinema booking system, all is well, just one thing left to do - a booking confirmation after seats are booked. I can get the page redirecting in Javascript and this is not the problem. In my mind I was thinking of getting the last lastInsertId() from the booking table, pass that to the success page, write some sql and be done with it. But my booking table looks like this: booking booking_id seat_id screening_id 57 399 2 58 400 2 59 751 96 60 752 96 So there are multiple lastinsertId Now, I was doing a hotel booking system before, so I just got the last id, which could have 1 or more rooms attached to the id and then I could do my sql for the confirm page. This is different - there can be 1, 2, 3 or more tickets. And as you can see above each record has a booking_id - which makes sense because it identifies a single ticket each time. But how do I go about this confirm page? Do I write some code to pull the latest booked tickets, say someone logs on and books 3 tickets - do I remember that 3 tickets were booked, get there booking_id and go from there? But how would I know how many tickets the user just booked? I could do it by screening_id, but in between the transaction someone else could have booked tickets for the same screening. Any advice/logic would be welcome Thanks Edited February 26 by webdeveloper123 Quote Link to comment Share on other sites More sharing options...
Barand Posted February 26 Share Posted February 26 If they book several seats you will have several booking_ids. What will you do with them when you have them? The reason for getting the last insert id is to use it as a foreign key when you post child records (eg write invoice header then invoice item records). From your data model this isn't the case. Quote Link to comment Share on other sites More sharing options...
webdeveloper123 Posted February 26 Author Share Posted February 26 (edited) 17 minutes ago, Barand said: What will you do with them when you have them? Build a confirmation page like "Booking successful" Here are your booking details: Wonka Monday 26th Feb 19.00 Screen 5 Seat Numbers: C-1, C-2, C-3 Price: £24.66 Edited February 26 by webdeveloper123 Quote Link to comment Share on other sites More sharing options...
Barand Posted February 26 Share Posted February 26 You don't need the ids for that. try { begin transaction insert seat booking(s) commit exit('OK') } catch (exception) { rollback exit('Error') } Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted February 26 Share Posted February 26 37 minutes ago, webdeveloper123 said: This is different not really. you are doing the same operation, only the name/meaning of the data is different. you should have a booking/reservation/order table, that holds the unique/one-time booking data. a single row is inserted into this table when someone submits an order. this row produces a booking id (the autoincrement primary index.) you would use this booking id to store the related booking item data, one row per item, which in this case is the seat id, screening id, ... Quote Link to comment Share on other sites More sharing options...
webdeveloper123 Posted February 26 Author Share Posted February 26 That is actually the format my code is in (try, catch) But how do I get those attributes on a success page - redirect in php rather than JS and use GET? Quote Link to comment Share on other sites More sharing options...
webdeveloper123 Posted February 26 Author Share Posted February 26 5 minutes ago, mac_gyver said: you should have a booking/reservation/order table Can I use the table in my original post or Do I have to create a new table? Quote Link to comment Share on other sites More sharing options...
Solution Barand Posted February 26 Solution Share Posted February 26 I am assuming that this is an AJAX/Fetch process as you reference javscript in your initial post. Is it? Quote Link to comment Share on other sites More sharing options...
maxxd Posted February 27 Share Posted February 27 Structure-wise, I agree with mac_gyver. This is really no different than the hotel booking system you were working on before. A single cinema booking can consist of multiple seats, much like a single hotel booking can consist of multiple rooms. Take a step back, think about what you know from past experience, and re-evaluate your current data design; in this case I very much doubt that a "booking" is a single seat. Quote Link to comment Share on other sites More sharing options...
webdeveloper123 Posted February 27 Author Share Posted February 27 (edited) 22 hours ago, mac_gyver said: you should have a booking/reservation/order table, that holds the unique/one-time booking data 22 hours ago, mac_gyver said: you would use this booking id to store the related booking item data, one row per item But as in the original post, my booking table is there, I have different booking_id per seat, even if the seats were purchased together. So, surely, If I Buy 2 tickets right now, the booking_id should be the same. Like in the hotel system, if a user booked 4 rooms at once, the booking_id would be same for all four. I don't have that, I have different booking_id per seat, even if the seats were purchased together. 18 hours ago, Barand said: I am assuming that this is an AJAX/Fetch process as you reference javscript in your initial post. Is it? No. I mentioned JS in the initial post, but only the redirect is done in JS, there is no fetch call to the success page. Here is the relevant snippet: setTimeout(() => { updateSelectedSeat(); alert("Seats booked successfully!");window.location.href = "success.php"; }, 500); JS is in the same state as my previous version when you and mac_gyver helped me show seats that are already booked on the cinema seat map. I achieved that, since then the only change to the JS is the line: window.location.href = "success.php"; 12 hours ago, maxxd said: A single cinema booking can consist of multiple seats That's the thing, I don't have that in my database. I have the booking table sample data in my original post, but there is not a single booking_id attached to many seats like there should be. Do I have to go back and change my data model? Or can there be a surgical intervention & put a band aid on it? Because after this success page is done, that's it with this project, its on to the next one. Or shall I just use GET variables into this url: window.location.href = "success.php"; Edited February 27 by webdeveloper123 Quote Link to comment Share on other sites More sharing options...
webdeveloper123 Posted February 27 Author Share Posted February 27 Update: I got it, its fixed now. Thanks for all your input guys Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.