1
00:00:01,170 --> 00:00:08,010
So now we want to handle the situation where someone clicks save on this screen and allow them to update

2
00:00:08,010 --> 00:00:09,760
the reservation, and that's really simple.

3
00:00:09,780 --> 00:00:11,450
So let's go create the handler first.

4
00:00:12,090 --> 00:00:15,180
So we'll go back to our code and find handlers.

5
00:00:15,570 --> 00:00:19,920
And we are using a function called Admin's Show Reservation.

6
00:00:19,920 --> 00:00:21,150
So let's just copy this.

7
00:00:25,780 --> 00:00:32,120
And create a new function right underneath this one and change the name to post admin post show reservation.

8
00:00:33,370 --> 00:00:37,840
All right, so the first thing we want to do, when you think about it, we're only getting some of

9
00:00:37,870 --> 00:00:43,700
the information for a given reservation and we want to update it in the easiest way possible.

10
00:00:43,720 --> 00:00:50,080
So what I'm going to do is grab the ID and we'll grab the ID the same way we did here and also get the

11
00:00:50,080 --> 00:00:51,550
source the same way I did here.

12
00:00:52,180 --> 00:00:58,630
So I copy all of this code, paste it in here, and then I'll get the reservation by ID because I now

13
00:00:58,630 --> 00:00:59,290
have the ID.

14
00:00:59,320 --> 00:01:04,690
So Rez and Error are assigned the value of M DB.

15
00:01:04,810 --> 00:01:12,460
Don't get reservation by ID and I'll pass it ID and I'll check for an error and I'll just copy and paste

16
00:01:12,460 --> 00:01:15,070
this because I have it all over the place so that's easy enough.

17
00:01:18,340 --> 00:01:20,850
And then I'll update the reservation with what's been passed.

18
00:01:20,860 --> 00:01:27,580
So resort first name is equal to ARG form get first name.

19
00:01:29,500 --> 00:01:32,160
I have to remember to pass the form before I get too much further.

20
00:01:33,040 --> 00:01:33,940
Last name.

21
00:01:34,540 --> 00:01:35,410
His last name.

22
00:01:37,960 --> 00:01:39,850
Email is email

23
00:01:42,730 --> 00:01:46,780
and phone is phone.

24
00:01:48,880 --> 00:01:50,530
OK, now let's pass the form.

25
00:01:50,540 --> 00:01:53,560
I'll just see where I do this or copy it from somewhere else.

26
00:01:54,220 --> 00:01:57,220
PERS form right there.

27
00:01:57,730 --> 00:02:04,720
Some will copy this, go back down to the bottom and put that person form in as the first thing that

28
00:02:04,720 --> 00:02:05,110
we do.

29
00:02:05,830 --> 00:02:09,130
OK, and here I don't want to take them to a page like that.

30
00:02:09,130 --> 00:02:15,160
I just want to go with server error because this is a administrative back end and I'm less concerned

31
00:02:15,160 --> 00:02:19,990
about pretty error pages here because it's just something I'm going to use.

32
00:02:20,920 --> 00:02:21,340
All right.

33
00:02:21,340 --> 00:02:22,510
So I've passed the form.

34
00:02:22,510 --> 00:02:26,150
I now have updated my reservation model that I just pulled from the database.

35
00:02:26,150 --> 00:02:31,150
So when I pulled it from the database, it had us has all the values that were in there prior to any

36
00:02:31,150 --> 00:02:32,170
changes that we're going to make.

37
00:02:32,410 --> 00:02:37,810
And then I just override the four things that are possibly changing and I would just update the database.

38
00:02:38,620 --> 00:02:42,940
So error and I only have error declared somewhere.

39
00:02:42,940 --> 00:02:50,830
So I don't have to define or use the assign a condition to ecocide IMDB DOT update reservation and pass

40
00:02:50,830 --> 00:02:51,490
it my rez.

41
00:02:52,180 --> 00:02:55,900
And then again, if there's an error, give me the server error.

42
00:02:56,830 --> 00:02:58,860
Otherwise where do I want to take them.

43
00:02:58,870 --> 00:03:02,110
Well I want to take them when they save the changes.

44
00:03:02,530 --> 00:03:09,100
Probably back to the list of reservations, either the new or the the all.

45
00:03:09,100 --> 00:03:11,980
So I can just say htp dot redirect

46
00:03:14,860 --> 00:03:24,610
w our admin reservations dash and then I'll put a percent s in there and we'll make this a format as

47
00:03:24,610 --> 00:03:35,830
Pranav and replace the placeholder with my source and then I have to give them a status status c other

48
00:03:36,850 --> 00:03:37,720
and that should be enough.

49
00:03:37,810 --> 00:03:38,880
You can put a message in there.

50
00:03:38,890 --> 00:03:40,570
I should just put my message in there.

51
00:03:41,590 --> 00:03:43,270
M dot app.

52
00:03:43,630 --> 00:03:45,310
Dot session dot put.

53
00:03:48,570 --> 00:03:52,830
Out of context, flash

54
00:03:55,350 --> 00:04:02,010
changes saved there that should do it all right now, obviously, I have put no error checking in here

55
00:04:02,010 --> 00:04:02,430
at all.

56
00:04:02,790 --> 00:04:06,630
And one of the things that I would do in production, of course, is put air checking in here.

57
00:04:06,990 --> 00:04:10,500
And I would also put air checking in using JavaScript, as we've done before.

58
00:04:10,620 --> 00:04:12,120
We've been over that several times.

59
00:04:12,120 --> 00:04:14,460
And you should be able to handle that on your own.

60
00:04:14,670 --> 00:04:18,990
If not, look at the source code that I post at the end of this section for everything that's completed

61
00:04:18,990 --> 00:04:19,920
up until that point.

62
00:04:20,160 --> 00:04:21,780
And you can see how I did it.

63
00:04:22,050 --> 00:04:26,640
But for now, I just want to get through the updating part and not cover ground.

64
00:04:26,640 --> 00:04:28,700
We've already covered several times.

65
00:04:29,250 --> 00:04:33,840
So let's stop the application, start the application and see what we got wrong, if anything.

66
00:04:34,770 --> 00:04:39,360
So I'll come back to here, reload this and I'll put an R after the first name.

67
00:04:39,510 --> 00:04:43,590
And this is for reservation ID five so I can find it again if I have to.

68
00:04:44,430 --> 00:04:45,510
And it takes me nowhere.

69
00:04:45,660 --> 00:04:46,440
I got an error.

70
00:04:46,470 --> 00:04:47,220
What did I get.

71
00:04:48,240 --> 00:04:48,690
Nothing.

72
00:04:49,140 --> 00:04:50,550
Oh, you know what I didn't do?

73
00:04:51,360 --> 00:04:53,400
I didn't put the necessary handler in place.

74
00:04:53,400 --> 00:05:03,390
So let's go back to the roots and find this and change that to a post and have it to go to admin post

75
00:05:03,630 --> 00:05:07,140
show reservation and get rid of the extra text here.

76
00:05:07,830 --> 00:05:12,510
Stop the application, run the application and try that again.

77
00:05:12,510 --> 00:05:14,430
So we'll go to the dashboard.

78
00:05:20,070 --> 00:05:26,250
And we'll go to Reservation's new reservations, look at the very first one at an hour and click save

79
00:05:27,090 --> 00:05:30,480
and go back to here and it did change it.

80
00:05:30,510 --> 00:05:30,960
That's good.

81
00:05:31,020 --> 00:05:32,980
OK, so let's cancel.

82
00:05:34,230 --> 00:05:34,720
Perfect.

83
00:05:35,220 --> 00:05:39,900
Now let's change the last name or her save that worked.

84
00:05:42,960 --> 00:05:44,240
And it did it everywhere.

85
00:05:44,310 --> 00:05:46,240
Oh, I made a mistake in my school somewhere.

86
00:05:46,590 --> 00:05:48,810
Let's go have a look at our school for the update.

87
00:05:51,450 --> 00:05:56,540
And here, yes, look at that.

88
00:05:56,550 --> 00:06:00,540
I updated absolutely all of the records because they didn't put a clause in there.

89
00:06:00,960 --> 00:06:06,570
As I said a little while ago, I think I need more caffeine where ID equals dollar sign six.

90
00:06:08,910 --> 00:06:10,230
And that would come from.

91
00:06:13,060 --> 00:06:14,850
You got ID?

92
00:06:16,500 --> 00:06:17,600
OK, let's try that again.

93
00:06:18,430 --> 00:06:19,630
Stop the application.

94
00:06:22,980 --> 00:06:31,680
Run the application, it's running, let's reload this page and change just this one, I'll get rid

95
00:06:31,680 --> 00:06:34,380
of the extra hours and it should just change that one.

96
00:06:36,400 --> 00:06:37,060
Five.

97
00:06:38,430 --> 00:06:42,720
Did and now change just that one and it changed it.

98
00:06:42,750 --> 00:06:48,600
All right, well, that was an easy mistake to make, but one that could have had catastrophic consequences

99
00:06:48,600 --> 00:06:54,510
if I was working on live data, which is why I never, ever work with live data and neither should you.

100
00:06:55,290 --> 00:06:56,960
OK, so we've got that part down.

101
00:06:57,450 --> 00:07:04,380
Now, the next step will be to actually add a button that allows us to make a reservation as processed,

102
00:07:04,380 --> 00:07:09,870
but only have that button show up if it is one that has not been processed and to add a button to delete

103
00:07:09,870 --> 00:07:10,020
it.

104
00:07:10,020 --> 00:07:12,360
And we'll take care of that in the next lecture or two.
