1
00:00:01,260 --> 00:00:07,420
So let's modify the form just enough that we'll be able to test our database function to insert a reservation.

2
00:00:07,860 --> 00:00:11,160
So let's go look at the form right now.

3
00:00:11,190 --> 00:00:15,710
We just have first name, last name, email and phone, and we need to add some things.

4
00:00:15,720 --> 00:00:20,190
And what we need to add our first name, last name, email, phone.

5
00:00:20,190 --> 00:00:23,960
We need start date and date room ID and that's all we need to add.

6
00:00:23,970 --> 00:00:25,470
Everything else is taking care of us.

7
00:00:25,470 --> 00:00:28,790
And this is something we're not using, but we might at some point in the future.

8
00:00:29,460 --> 00:00:36,600
So we need to add start date and date and remedy what we can do that will go over to our template,

9
00:00:36,690 --> 00:00:42,360
which is under templates and we'll find make a reservation page.

10
00:00:42,630 --> 00:00:43,170
There it is.

11
00:00:43,920 --> 00:00:44,220
All right.

12
00:00:44,220 --> 00:00:47,960
Let's just put a couple of fields in here just for the sake of making this work.

13
00:00:47,970 --> 00:00:55,860
So what I'll do and it doesn't even matter what they look like at this point, we'll just say div we'll

14
00:00:55,860 --> 00:00:59,580
put them below the first name and last name just for just we'll put them in here for now.

15
00:00:59,580 --> 00:01:01,320
It doesn't matter where they go, we'll clean this up later.

16
00:01:01,950 --> 00:01:05,820
Div class equals form group

17
00:01:08,520 --> 00:01:18,600
and then a label label four equals start date and start date and then an input.

18
00:01:21,600 --> 00:01:35,250
Type equals text, name equals start date, ID equals start date and class equals form control.

19
00:01:36,270 --> 00:01:37,560
All right, copy this.

20
00:01:39,540 --> 00:01:42,380
And I'll paste it, then I'll change it to end date.

21
00:01:49,840 --> 00:01:57,130
And then we need a remedy, and I'll just do that as a hidden field input type equals hidden name equals

22
00:01:57,490 --> 00:02:03,670
room ID value equals one, and we don't have a value equals one in the database yet.

23
00:02:03,680 --> 00:02:04,990
So we have to add that in a moment.

24
00:02:04,990 --> 00:02:06,610
But let's make sure that our form looks right.

25
00:02:07,660 --> 00:02:08,950
OK, we've got to run the application.

26
00:02:16,380 --> 00:02:20,200
And there it goes and a fantastic on my computer for some reason, I apologize for that.

27
00:02:20,220 --> 00:02:21,280
Hopefully it will stop soon.

28
00:02:23,010 --> 00:02:27,270
It is running and we have a start date and an end date so we can populate that.

29
00:02:27,270 --> 00:02:29,780
And our hidden field should be right between these two.

30
00:02:30,210 --> 00:02:30,950
So we're good to go.

31
00:02:31,530 --> 00:02:32,820
So we have that now.

32
00:02:32,850 --> 00:02:35,430
We need to put something in our room table.

33
00:02:37,710 --> 00:02:48,060
So wrong application this one, and I'll connect to my local host and I'll go to my bookings and I'll

34
00:02:48,060 --> 00:02:51,210
find rooms and it's currently empty.

35
00:02:51,210 --> 00:03:00,300
So let's adoro and I'll call this one Generals' Quarters and put it in a date here and here.

36
00:03:07,350 --> 00:03:09,120
And if I save this, I now have.

37
00:03:13,160 --> 00:03:18,370
I now have an entry in my database perfect, so I should be able now to fill this out with valid data.

38
00:03:18,380 --> 00:03:28,100
ABC C start date 2020, say eleven thirty to twenty twenty 12 02.

39
00:03:28,370 --> 00:03:32,810
My email is me here dossier and my phone is five or six.

40
00:03:32,810 --> 00:03:34,310
Five or six or six or six.

41
00:03:34,310 --> 00:03:35,390
Six, six, six six.

42
00:03:36,050 --> 00:03:39,410
And hopefully this will work and it does.

43
00:03:39,460 --> 00:03:45,830
OK, now let's go look at our database and check the reservations table and there is everything that

44
00:03:45,830 --> 00:03:46,430
I need.

45
00:03:46,940 --> 00:03:47,510
Perfect.

46
00:03:47,510 --> 00:03:50,270
So we can add some information to the database.

47
00:03:50,990 --> 00:03:54,170
Now, that's only one step if you think it through.

48
00:03:54,620 --> 00:04:01,880
When we go back to our code here, to our handlers after we insert the reservation, we need to do one

49
00:04:01,880 --> 00:04:03,710
more thing before we can redirect them.

50
00:04:03,980 --> 00:04:07,040
We need to insert the reservation restrictions.

51
00:04:07,040 --> 00:04:12,230
So we need to go to the room restrictions table, which would be right here.

52
00:04:12,860 --> 00:04:14,390
And it requires some things.

53
00:04:15,500 --> 00:04:16,850
It requires the start date.

54
00:04:16,880 --> 00:04:17,510
I have that.

55
00:04:17,660 --> 00:04:18,860
It requires the end date.

56
00:04:18,890 --> 00:04:19,580
I have that.

57
00:04:19,970 --> 00:04:21,350
It requires the room ID.

58
00:04:21,410 --> 00:04:22,160
I have that.

59
00:04:22,790 --> 00:04:24,710
I don't have the reservation ID.

60
00:04:25,160 --> 00:04:29,480
I know what the restriction ID is going to be, but I have to populate some entries in the table before

61
00:04:29,480 --> 00:04:30,140
I can do that.

62
00:04:30,500 --> 00:04:31,670
And these two are no problem.

63
00:04:31,670 --> 00:04:39,020
But this one, the reservation ID I don't have and I don't have it because in my database routine which

64
00:04:39,020 --> 00:04:40,760
is under the postgres don't go.

65
00:04:41,540 --> 00:04:43,730
All this gives me back is an error.

66
00:04:43,850 --> 00:04:49,670
So I need to modify this to actually return the ID of the newly inserted reservation.

67
00:04:50,870 --> 00:04:56,270
Now if you're familiar with something like MySQL or Maria DB, you know that you have access to a function

68
00:04:56,270 --> 00:04:59,420
called Last Insert ID and that's really easy.

69
00:04:59,420 --> 00:05:00,830
You can just call the function.

70
00:05:00,950 --> 00:05:04,850
What's the last insert ID and the connection will hand it back to you.

71
00:05:04,850 --> 00:05:07,100
And then you have the ID of the inserted record.

72
00:05:07,580 --> 00:05:11,840
Postgrads doesn't have that, but PostgreSQL does have something called returning.

73
00:05:12,200 --> 00:05:18,830
So I can say returning ID, but that means I need to change the way that I'm making the query from an

74
00:05:18,830 --> 00:05:20,510
execute to something else.

75
00:05:20,780 --> 00:05:22,940
So we'll take care of that in the next lecture.
