Welcome back.
Now it's time to fix many bugs that we have.
And we and whenever you create a big project, you will definitely have so many bugs.
And you need to be very careful because otherwise your application could be very vulnerable to many
problems.
So the first thing that we have here is that here, if you open up the place, order up, you'll find
that I'm allowing users who are not logged in to place an order.
And this is a problem because if they if the user is not logged in, there should be there.
There is no user ID.
And if we try to place an order, we we are going to get an error.
So this is the first problem that we have.
Another problem is that there it's better to protect the excuse.
It's better to check the execute before proceeding and executing the code below.
So this excuse will always return true or false?
If if if this goes through, it means that the the ill statement has been executed successfully else.
If it returns false, it means that there is a problem.
So it's better to add here now if statement and check whether this is this return true or false.
This is the second thing that we need to do.
The third thing that we need to do is that if user is not logged in, they shouldn't be able to to to
place an order.
So let me fix all of these things.
The first thing that I'm going to do is that here I'm going to add a statement.
I'm going to say if and then I'm going to say if execute is false.
If here if false.
By the way, you can do something else.
You can say here is the empty underscore status is equal to this.
And then you can say if is the empty underscore status.
Is false.
If exclamation mark, which means it's false.
If it's false, we should use the header and then take the user to the to the index page or any page
you want.
You shouldn't continue.
You should just take the user somewhere else and you should exit.
This is very important.
You should exit because if you do not exit, it's going to continue executing the code below.
And you can display an error message message if you want.
But the possibility of this being false is so slim because because if we have these things and we already
made sure that we have the email and the password and and the the email, the name of the email or if
one of the city.
Because they form the form in the in the place.
Let me show you that.
In the place order here in the check out page.
The user will not be able to place an order without filling out this form.
So we are 100% sure that the user will provide us with these things.
The only problem is with the.
Is with the.
The user I.D. So we need to make sure that the user is locked in.
Also, if the user is if the court is empty, we already handle this.
We already handle this.
If the card is not empty.
If the court is empty, then it's going to take the user to the index page.
So this is protected.
Therefore, here in the police order, the only problem that we could have is the decision being the
session user ID being empty.
So which means that the user is not logged in.
So the only thing that we need to do is that we need to make sure that the user is logged in similarly.
Similarly here, if we have a problem, it's better to protect this.
But again, again here we already know that the card is not empty at this point.
And at this point, the product ID and the name and image and the price and the quantity, all of them
will never be empty because you have inserted these in the database.
There is no way that these could be empty because here in the in the card, if you check again, if
we check the card, we fill the card with these things.
So it's it's like 99.9%.
So it's 99.9%.
Not going to be empty.
And this is not I'm not saying this, I I'm saying this because we already protected these in other
pages.
So adding just adding so many statements is also not a good practice.
So you need to check, read your errors once before moving on.
We have already done that already here, by the way.
Here in case user places an order successfully.
We actually shouldn't keep the card
filled with products.
And I'm going to work on this later.
Let me now focus on making sure that the user will not be able to place an order unless they will get
and to do this here in the place order, that would be the first thing that we need to do is that we
need if statement here and then we need to say if not is set session.
Session.
Logged in.
Logged under score ein.
Then if the user is not logged in then we need to say header and then we need to take the user to the
check out page or any page you want.
It doesn't have to be the check out.
You can take the user through the index or the check out or even the account or even the log in.
So I'm going to here say location, first location, and then I'm going to say check first that because
we are the place order is inside is inside the server.
So we need to go back one step back and then access the checkout.
So we need to say here dot that and therefore slash check out not B2B.
And then the message I'm going to say message and the message is going to say, please log in.
Slash register to place an order.
And most importantly, you need to exit.
This is very important.
You need to exit.
This is very, very important.
So you have to exit.
If you don't want to exit, then you can add ILS and then place all of this good inside this else here.
Like this.
So all of this code can be pushed inside this, Elise.
So this is, I think this is more, um, uh, meaningful now that you can see if a user is logged in
and if a user is not logged in.
If user is not.
This is a comment, by the way, not logged in.
And again, if you don't want to use the alpha, you need to say your exit.
Exit.
But exit here would be redundant because we have else.
Anyway, he's now in the check out.
We need to display this message.
So in the check out, the first thing that we need to do is that we need to remove this.
Check out boss.
Check out.
The reason is because if you don't remove it and redirect the user from the place order to this page,
it's always going to take the user to the index.
So we need to remove this check out from here.
I'm going to remove it from here and we just need to check if user is.
If user is, um, if the card is not empty.
And finally, we just near here need, we need to display the error message.
We need to say.
We need to hear about reform or.
Or you're actually here about reform or.
Or.
Or above this.
Above or below this form.
You can use a p and then.
BHP.
And first you need to check.
You need to check if is set.
Get.
And then message.
Then at this point, we need to echo the message.
We need to say echo and then echo what?
Equally.
Get message.
And here I'm going to say.
Glass.
And then next.
Center.
And I'm going to also say style.
Color red and you can display a link so that the user logs.
So that they use an analogy.
So you can hear here, you can add another statement here, or you can by the way, you can close this
you can close this beach.
B And then, um.
And then here you can display a button.
You just.
Here.
Display a button.
Let me keep this.
Let me keep this line as it is, because I don't want to confuse you.
This is going to be complicated.
Let me just keep this and be law.
I'm just going to check.
Get another check.
Another beach B with a.
If.
Is it again a safe get message?
Then your daily bracket and then close the candy bracket each be.
Close the Kennedy bracket and then you can hear this play the.
You can display the attack with the with with a link to log in.
And then here you can see and log in and then you can again you can say class and then Beattie and.
And then you can even say BP in primary.
And the sheriff at this point.
The sheriff is going to be.
Equal to log in that BHP.
And here we need to say like this.
And that's it.
Now let me go back and let me add another to the cart and let me try to place an order.
So I'm going to here click on checkout.
And if I click on place order, first of all, I will not be able to place an order because I have to
feel this lady feel this.
So if I fill out this form and click on place order, as you can see here, it's going to say, please
log in, register to place an order so this button is not going to work unless you log in.
And if you click on log in, it's going to take me to the log in page.
Now, I will not be able to place an order unless I feel this.
And then look at the first log in, actually.
So this is very important.
You need to not to allow users to place orders before they log in.
You can even add this go to the cart.
You can prevent users from coming to this page altogether before before even clicking on on the card
here.
Before clicking on on this button, check out.
So now let me test let me now log in first.
Let me log in and try to try to.
To place an order after you log in, because now if I try to place an order, I will not be.
So again, if I click on place order, it's not going to work.
So I first need to log in and if I log in, let me log in at least on order.
So if I click on log in now, I will be able to log in.
And if I go to the card, let me go to the card.
I'm going to here go through the card.
I'm going to say card.
And now in the cards.
Oh, let me check out.
And leave me here.
Fill out this form.
Now, if you click on Place Order, as you can see, the order will be placed and you will be taken
to the payment page.
So it worked successfully and I will only be able to log through to place an order if I am logged in.
So this is very, very important practice you need to have.
Also, if you are logged in but the cart is empty, you will not be able to place an order.
Let me show you this.
So let me show you this.
So here I'm logged in, right?
If I remove this from the cart.
So now the cart is empty.
And if I click on check out, I will not be able to.
So this is very important.
Now our system is protected.
The user will have will have here in the in the chain.
And they cannot be in the actually in the check out.
We have here the if the cart is empty, then if the cart is not empty, the user will be let in it.
Also, the user will be taken to the through the index, also in the police order before the user places
an order.
We need first to check whether we are looking or not.
And again, I need to emphasize on adding this good in in the check out is also possible you can protect
this the you can make the protection from here or from here or even from the cart.
Which is it also?
It's just the same goal.
It's just the same goal, but a different method.
So you can follow any method you want.
But the goal is to protect the but the placing an order page because you shouldn't allow users to place
orders without logging in and without having something in the cart.