Welcome back.
Now, what we need to do is that we need to get the data from the form and use it in records.
But before I do so, I need also to pass another input.
I need to pass the ID, the product ID.
So I'm going to get another input here and I'm going to say type hidden.
And the name and the name is product ID.
Product ID.
And I'm going to need value and the value is as usual, BHP and then echo and then.
Raw.
And then.
Semicolon and the product.
Product item.
Product I.
That's it.
And you forget to close this stack, and we are good to go.
Now, in the car, the most important part is here.
Here.
Before we display the cart.
Before we display the cart, the first thing that we need to do is that we need to get the data from
this single page.
Because when you click when you click on Add to Cart.
We will take the user to the car, but we need first to display the data here, to display the products
that the user or the product that the user added to the card.
We need to get to get it from the from the single product that B2B.
So here, before we do anything, we need to use the session to do this.
So I'm going to start by saying here.
Session, session, start.
Session start and then we need to check whether the the boss parameter is empty or not.
So we do use the set function and this is set function is going to check whether the whether the user
came to this page using the form or not.
So I'm going to say add underscore to cart.
And then else.
So this basically this is said post after card is going to check whether the user clicked on add to
cart button or not.
If if user clicked on add to cart, then we need to move on and continue with the cart.
Else it means that the user tried to get to the cart page from some somewhere else.
And we don't at this point we need to probably take the user to the do the previous page or do something
else.
So in this case, we need to do something else, maybe take the user to another page or or maybe we
can take the user to the to the all page or the index.
We can see a location.
Index, not BHP.
Okay.
So here after we made sure that the user came to the Spanish by clicking on this button, by clicking
on the on this button, we need now to check the session.
So I'm going to say if, if session if, if is set.
If a set.
Session.
Mm hmm.
And then I'm going to give you a session called Shopping.
Can't.
Or let's say, just for the sake of simplicity, I'm going to say cars.
Efficient cars is if we have a card, if if the user has already added something to the card before,
then we need just to add more to this card.
Else.
Else it means that the user it means that this is the first product that the user is attempting to add
to the card.
So here I'm going to say if this is the first product.
And here if.
If this if user has already.
Added.
A product to cart.
So if if user has already.
If user has already added something to cart, it means that the cart is not empty.
If this is the first product, then we need to add it to CART as the first product.
So here the first product record is going to be like this first.
We need to create the session from from scratch because this is the this is the first product.
So we need to say we need to get the the data from the from the POS request.
So to get the data from the past request, we can say based then remember the parameters that we passed
are for the image, name and price.
So we need to say here project.
Underscore it.
And it's going to be equal to your product I.D. So product I.D. is going to be equal to this.
And then we need to repeat the same thing for other parameters.
So I'm going to copy this and paste it three times.
Here and here and here.
So we need it.
We need product.
I need.
We need product.
Price.
We need product.
Image and we need product.
I think quantity.
Product.
Name.
Quantity.
One.
And then I'm going to store these in variable.
So I'm going to use the variable called product.
The name is equal to this and then product.
Price is equal to this.
And then.
Right act.
Image is equal to this.
And lastly.
Project.
Quantity.
Is equal to this.
Now we need to add these parameters in in a single area.
So I'm going to do it here and a equal product array.
And then I'm going to say it's going to be equal to Iran with these guys.
So we need to say product.
Let me add this in a new line first semicolon and then in a new line so that you see the structure.
I want you to recognize the structure.
I'm going to say product I.D. is going to be equal to the product.
And then.
Comma and then the product's name.
Product name.
Is equal to or nickname.
I think comma and then product.
Price is equal to the price.
And then project.
Image.
Is equal to the image.
And then product quantity right at 180
is equal to the product quantity.
So we have all all of these finally, we need to add this area to this issue.
So what I did is that is that I took the data from the single page, which then here from the past request,
and then added them to two separate and individual parameters.
And then I collected them using this array.
And then I'm going to add this array now to the session.
So I'm going to give you the session here.
I'm going to say a session with a key called Card.
Guard.
And the the in order to recognize this this product, we need to give this array a unique I.D. And to
give this this array a unique I.D., we can use the product.
So I'm going to say here right at Andy Roddick, it is going to be equal to the product.
All right.
So let me explain this.
I know that this is confusing right now.
Now, what I did here is that I created a session and that session isn't all right.
So this session let me show you the structure.
So the structure is going to be this session can can store anything.
So it's going to in this case, this session is going to store a store, an array.
And in this array in this array, we have another area, which is this product area, but this product
array, in order to recognize this product, everything we need to give it a unique ID.
So the ID is going to be the product ID.
So, for example, if the product I.D. is true, then I'm going to store to with the product ID.
So this is the product, maybe this is going to represent the product ID and the key is going to represent
the product ID is going to be the product in order to recognize this product.
This in order to recognize this product array.
Because if we add more products, we need to also give them unique ID.
So for example, if I add product three, I'm going to say three is equal to another, right?
And then if I add another product to the record, I'm going to say, for example, five two is equal
to another array.
So each array that I'm going to add to the cart must have a unique I.D. And this is the structure of
the array of recession, right?
So the session array is a big array.
And inside it we will have given you pairs where the key is the product ID and the value is the array
itself is this array that contains the information about that specific product.
That way I will be able to recognize and distinguish between products that have been added to the cart.