Welcome back.
The next step is, is that we need to get the products from the cart and insert each single product
into the into the order items.
So each single item we have will that the user box will be inserted individually into the into the database.
So again, if the user, for example, wants to buy these, do we need to insert each one individually
into in a separate raw in the database so that we know each item or which items the user wants.
So here the second step first, before I move, before I work on the second step, I'm going to remove
this echo.
We know we no longer need this echo.
So the second step is that we need to get products from the cart.
So to get the products from the cart, we need to use the session because the decision has.
The station has the card and this card is NRA.
And since this card is NRA, it has the it has this structure.
It has key value pair where each key represents a an order, represents a product ID and the value is
an array with the information about that product.
So for example, if we have two products in the card, the first key, the key is the product ID and
the value is an array with product information such as the product price, the product name, the product
product description.
So what we want to do is that we need to use a for each loop in order to loop over for each in order
to loop over the session and get each single product and store it in the into the order items database.
So I'm going to say you for each and then for each white for each session.
Garth, and I'm going to remove this.
We no longer need this.
So I'm going to thank you for each session card as he.
Value.
We want to get each single area.
So in order to access each product, we need to say product.
Product is going to be equal to is going to be equal to session.
Cards.
And then keep.
This is going to get each single product as an entry.
So this is going to return an area where the product and now we can get each single.
It's each single or each piece of info that this product has.
For example, each product we can say product our product name, remember in the cart restored, we
store them in these keys.
So we have the product ID, product name, price, image, quantity.
So you need to use these keys.
You cannot use other keys other than these.
So we need to say here product, underscore item and then the product ID is going to be equal to.
Project ID is going to be equal to the product product and we can repeat the process and it's going
to take some time.
So let me let me work on this quickly.
I'm going to say product name.
And again the name is the key for the for the name is name price image quantity.
So here name.
And then.
Project.
Image.
And then.
Product.
Price.
And then.
Right act.
130.
And here once again you need to double double check your easier because if you have a mistake here you
will have a severe problem and you will not be able to figure out the problem easily.
So you need to double check before moving on.
Product ID Product Name.
Product Price.
Image Quantity.
Product Name.
Image Price.
Quantity.
Now we need to insert each single one into the database.
And to do this we can use the connection.
We can say con and then prepare and then insert.
In Syria.
In Insert.
Into.
Into what we need to insert into now into the order items.
So I'm going to say order underscore items, order items.
And then what do we want to insert?
We want to insert the, um, the order ID, the product ID, the product name, the product image,
the user ID and the order date.
And the.
The item ID is going to be given by the database automatically.
So we need to say here, we need to start with the product with the order ID.
So I'm going to say here, order underscore ID, comma.
And then the second is the product.
ID product.
I'd.
The third is product name and then image.
Product name and then product image.
And lastly, we have the.
User I.D. and the order, the user I.D. and then order date.
So the order date we have the order date, but we don't have the we have everything actually.
So let me add the new line first and then I'm going to say values.
The.
Values.
And you need to be very cautious because if you have any problem with this, with the syntax of this
school, it's not going to work.
So how many question marks?
Again, you need to use question marks because otherwise you will your data will be could be under attack
by hackers.
And again, if you are interested in Beachbody security and security best practices, you can take my
course about security best practices of BHP.
So here we need one, two, three, four, five, six.
We need to see six.
Question marks.
One, two, three, four, five, six.
And then we need to store this in a variable called the empty.
One, let's say, is the empty.
Just the empty.
Let's see, is the the one used to differentiate between this and the other one.
And then I'm going to say you.
The.
Is the empty one bind around.
And what are the parameters that we want to bind?
First, we need to bind the order ID.
So the order I.D. is is the integer.
The product ID is integer.
The product name is string.
The product image is string.
The user ID is integer.
The order date is.
A string and then comma and then.
Let's start with the order I.D..
So the order I.D. is here.
This is the order I.
I'm going to stay here.
Order.
I'd.
And then Project 80.
Project.
I did.
And then.
After the product I.D. We need the product name.
So we have the product name, product name and then the product image.
Product image and then the.
We also need the products price and quantity.
So I forgot to add here the product name and the price and the quantity.
So we need to adhere to the Laney idea.
Let me say.
Let me hear say.
Structure.
And let me add the product here.
I'm going to add.
The quantity.
The quantity is very important.
So I'm going to here I'm going to add two columns.
After the image.
And these columns are going to be the product price and the product quantity.
So the product price is going to be integer is going to be decimal, actually.
And is going to be.
He's going to be for six, let's say six to.
And the quantity is integer.
And that's it.
It's actually the missing.
Mm.
That this email so we have this email and seeks means that it's going to be six digits.
And two of these digits are going to be.
Two of these six are going to be the points are going to be digits after the point.
So let me click on Save and.
Now, if I click on product items, you will find that we have your product price and product quantity.
So this is correct.
Let me now go back and here let me insert after the product image, we need to say product, product,
underscore price and then comma, product underscore one duty and then comma.
And he is going to say, I assess ISIS and then the the price and the quantity are integers.
So we need to say, I, I, and then I guess and then here we need to increase the number of question
marks.
So I'm going to increase the question marks to eight because now we have eight parameters.
One, two, three, four, five, six, seven, eight.
And here I'm going to say product, image and then product.
Price.
And then product quantity.
And then.
Product.
The user.
User ID.
So the last the last parameter is the order date.
Order date and you can get the order date from.
Previously we have it and we have either the order date and the user I.D. so there is no need to create
it one more time.
Finally, we need to excuse the statement I'm going to say is the empty and then execute.
This is going to execute the statement and that's it.
This is for for this part.
So for this part, we just need to do this.
So let's now test, maybe save everything else.
Heading over to the browser and test.
So not only the browser, let me add these into the cart.
So let me first start from from the beginning, I'm going to go to the homepage and I'm going to click
on.
I'm going to add this to CART and I'm going to add another product to CART.
So we already have these products added to cart limit.
Click on checkout.
Let me fill out this form.
So after I filled out this form limit, click on place order.
And we have a problem here in line 47.
So the line 47, I have a problem.
It says 47, I should say, is the empty one.
So this is a simple mistake.
And they also have a problem with the here, I should say, order items with an and so as he told us,
a very simple mistake could cause so many problems.
So here order underscore items because the table is order underscore items with that is let's try one
more time.
So I'm going to go back to the home page and I'm going to add this to CART.
We already have this in the cards and let me click on checkout.
Now let me fill out this form quickly.
So after I have filled out this form, let me click on place order.
And as you can see, nothing will happen.
And because I didn't display anything but let's check the database now.
Only the orders in the order items we should have.
We should have two items.
As you can see, we have two items.
The first item is the is the white juice and the second item is green back and thus.
That's correct.
And the name of the images, the prices, the quantities, everything is has been stored here.
And notice something important.
The order ID is the same.
There already is four and four because the same person, which is me, has ordered these two in all
in one single order.
So the order is going to be one.
So the order is not order number four.
And this order, the details of this order, the details is this.
Are these two lines?
Are these through her eyes?
The details of the order are the white rose and the green back.
This is a very important concept, and by using the order I.D., we will be able to do awesome things.