So now we want to handle the situation where someone clicks save on this screen and allow them to update
the reservation, and that's really simple.
So let's go create the handler first.
So we'll go back to our code and find handlers.
And we are using a function called Admin's Show Reservation.
So let's just copy this.
And create a new function right underneath this one and change the name to post admin post show reservation.
All right, so the first thing we want to do, when you think about it, we're only getting some of
the information for a given reservation and we want to update it in the easiest way possible.
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
source the same way I did here.
So I copy all of this code, paste it in here, and then I'll get the reservation by ID because I now
have the ID.
So Rez and Error are assigned the value of M DB.
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
this because I have it all over the place so that's easy enough.
And then I'll update the reservation with what's been passed.
So resort first name is equal to ARG form get first name.
I have to remember to pass the form before I get too much further.
Last name.
His last name.
Email is email
and phone is phone.
OK, now let's pass the form.
I'll just see where I do this or copy it from somewhere else.
PERS form right there.
Some will copy this, go back down to the bottom and put that person form in as the first thing that
we do.
OK, and here I don't want to take them to a page like that.
I just want to go with server error because this is a administrative back end and I'm less concerned
about pretty error pages here because it's just something I'm going to use.
All right.
So I've passed the form.
I now have updated my reservation model that I just pulled from the database.
So when I pulled it from the database, it had us has all the values that were in there prior to any
changes that we're going to make.
And then I just override the four things that are possibly changing and I would just update the database.
So error and I only have error declared somewhere.
So I don't have to define or use the assign a condition to ecocide IMDB DOT update reservation and pass
it my rez.
And then again, if there's an error, give me the server error.
Otherwise where do I want to take them.
Well I want to take them when they save the changes.
Probably back to the list of reservations, either the new or the the all.
So I can just say htp dot redirect
w our admin reservations dash and then I'll put a percent s in there and we'll make this a format as
Pranav and replace the placeholder with my source and then I have to give them a status status c other
and that should be enough.
You can put a message in there.
I should just put my message in there.
M dot app.
Dot session dot put.
Out of context, flash
changes saved there that should do it all right now, obviously, I have put no error checking in here
at all.
And one of the things that I would do in production, of course, is put air checking in here.
And I would also put air checking in using JavaScript, as we've done before.
We've been over that several times.
And you should be able to handle that on your own.
If not, look at the source code that I post at the end of this section for everything that's completed
up until that point.
And you can see how I did it.
But for now, I just want to get through the updating part and not cover ground.
We've already covered several times.
So let's stop the application, start the application and see what we got wrong, if anything.
So I'll come back to here, reload this and I'll put an R after the first name.
And this is for reservation ID five so I can find it again if I have to.
And it takes me nowhere.
I got an error.
What did I get.
Nothing.
Oh, you know what I didn't do?
I didn't put the necessary handler in place.
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
show reservation and get rid of the extra text here.
Stop the application, run the application and try that again.
So we'll go to the dashboard.
And we'll go to Reservation's new reservations, look at the very first one at an hour and click save
and go back to here and it did change it.
That's good.
OK, so let's cancel.
Perfect.
Now let's change the last name or her save that worked.
And it did it everywhere.
Oh, I made a mistake in my school somewhere.
Let's go have a look at our school for the update.
And here, yes, look at that.
I updated absolutely all of the records because they didn't put a clause in there.
As I said a little while ago, I think I need more caffeine where ID equals dollar sign six.
And that would come from.
You got ID?
OK, let's try that again.
Stop the application.
Run the application, it's running, let's reload this page and change just this one, I'll get rid
of the extra hours and it should just change that one.
Five.
Did and now change just that one and it changed it.
All right, well, that was an easy mistake to make, but one that could have had catastrophic consequences
if I was working on live data, which is why I never, ever work with live data and neither should you.
OK, so we've got that part down.
Now, the next step will be to actually add a button that allows us to make a reservation as processed,
but only have that button show up if it is one that has not been processed and to add a button to delete
it.
And we'll take care of that in the next lecture or two.