Welcome back.
Now it's time to work on placing an order.
And placing an order is going to it's going to be a long process because you might think that the process
is you're just storing user information in the database, and that's not correct.
There are many, many ways in order to accomplish placing an order, eliminate break down the process
into few steps so that you understand.
So now the first step is that we need to open up the place, order that BGP Illini here, type the steps
that we want.
So the first step is that we need to get user info because of course in order to send the, the, the
product to the user, we need their email, we need their city, we need their phone number, we need
their address in order to send the package and products to them.
The second step is that we need to store.
You get user info and store store it in database.
In database.
The second step is that we need to store order information, order info, and to store the order information
information in database database.
We first need to get
products from cards.
So the second step is actually.
The second step is to get products from so many years.
Type one, I'm going to say one.
The first step is to get user info and store it in database.
The second step is to.
Get products from carts from from the station.
Actually bring me out of here at night.
I'm going to say from station so that you don't forget that the information is in position.
The third step is that we want to place store the ordering information in database.
So after we get the the the products from the station, we need to take these products and store them
in the database and issue a new a new order.
So we need to get a new order in the order stable and we need to store each individual product in the
order items.
So, for example, if I let me go back to the home page and explain the process, for example, if I
want to buy.
If I want to buy.
If I want to buy a pair of shoes and buy a bag, then each each one of these must be stored in the order
items.
But both of them.
Both of these items will have one single order because they belong to the same to the same person who
wants to buy these two.
So these two items will have the same order ID, but they will be stored in the order item so that we
know the items that the user wants to buy.
So here the third step is to store order info in database.
First I need to say here issue new order and store order info in database and finally store store each.
Single item in order items database.
And the last step is to remove every thing from car.
And.
And actually, this is the fifth step.
And the sixth step is to tell the user or inform informed user that.
Whether.
Every scheme is.
Fine.
Or there there's a problem.
There is.
A problem.
And if there is a problem, we need to tell them.
If everything's fine, we need to remind them to continue.
We need to take them to the payment page.
So this is the last step.
Let's start working on these steps.
So let's start on the first step.
So the first step is to get user info and store it in the database.
So in order to get the user info, we need to.
Head on over to the to the check out and get these fields from before.
So here we have the the names, name, email, phone, city address and place order.
So if the user clicks on place order, we need to get the name.
I'm going to say name is equal to last name and then we need to get the email.
And then we took get on.
And then we need to get the.
We need to get the phone and Siri and address.
We have Siri and address Siri.
First.
City.
And lastly, we need to get the Aussies.
So the address is going to be your past.
Address.
That's it.
Now.
We want to insert this into the database.
These are our values in the database.
And to do this, we need to import the connection.
Remember the connection class, the connection file, because the connection will allow us to connect
to the database.
So at the top here, I'm going to say.
Include.
And then since we are in the same file.
Replace or replace order that BHP is in the same file as the connection.
So we just need to say here connection, connection that BHP and before we forget we also need to say
session start because I'm going to be using this session later.
I don't want to forget because this is usually forgotten by so many developers.
So after we have this, we need to use the remember every connection we have.
Again, let me remind you that we have a variable called con, so we need to use this con here.
I'm going to say con and then.
Prepare and then we need to pass the statement.
So the statement is insert, insert.
Insert into into what we need to insert into the we need to insert into the.
The orders when you transition to the orders table.
So we need to insert into the order table here.
We need to insert into the order symbol.
I'm going to say insert into.
Orders.
And what do we want?
Insert.
We want to insert.
The order cost, the status, the I.D., the user, all of these things except for the IDI they ordered.
It will be given by the database automatically.
So we need to start by the order cost.
So the order cost, I'm going to say here, order underscore cost is the total amount and I'm going
to get this shortly.
The second thing that we need to insert.
Is the order status.
The order status is always going to be on hold.
So I'm going to say order underscore status.
The third thing is.
The user ID, so we need to get the user I.D..
I'm going to say user underscore ID and then we need the.
Fun.
User fun.
And then.
Use our phone and then city.
User Siri and then user address and order date.
User.
Address and then order.
The.
And then in a new line, I'm going to hear.
You're in a new line.
I'm going to add a new line and then I'm going to say values.
Values.
So what are the values?
The values are first.
For the order cost.
We need to get the costs from decision.
So what I'm going to do is that I'm going to say here order costs.
And to get our conversation, we just need to say session.
And then total.
This is going to get the total from the session and then the order status.
I'm going to say order underscore status.
The order status is whether the order has been paid or not.
If the order has been paid, then we need to.
I say, but we will allow users to to place orders without paying.
And then after the order has been placed, I'm going to allow users to pay.
So I'm going to say here, the the initial value is always going to be on all.
So enrolled means that the order has been placed but has not been paid.
And then user I.D., the user I.D. I'm going to get the user I.D. later when I allow users to log in
and register.
But for now, the user I.D. is always going to be one just for the sake of testing the the user phone
number.
We have the phone number from the forum.
We have the name and we have everything else.
Lastly, we need the order date.
So we need to see order underscore the.
So the order date is going to be a date.
The time.
Let's use the time now.
Or we can use the date function.
We can use date y.
Y is for the year month date and then our second our minutes seconds, which is which is this function.
Now we can pass these into the values.
So the first thing is the order.
The order cost.
So I'm going to say your order cost.
However, this is not a good practice.
We need to pass question mark.
So we need to see how many question marks we need to pass.
One, two, three, four.
Five, six, seven.
So we have seven inputs.
So I'm going to say your question, mark.
One, two, three, four, five, six, seven.
And if you don't understand why I'm doing this, this is for the sake of protection.
And you can take my course about beach protection and you will understand the reason behind this, because
this is going to protect the the form and it's going to protect your system from hackers.
And again, if you want to take that course, I highly recommend taking that course about beach security
best practices.
If you are interested in understanding and improving your HB security code and applying best practices.
Now we need to call a function here.
We need to store this in a variable called is the empty.
So esteem is going to be equal to conviction.
Prepare and then.
Is the empty.
We need to call a function called buying program.
And the parameters that I'm going to bind are the cost.
So the cost is the cost here.
The cost is integer I.
And then the order status is going to be.
Yes, string user ID is I is integer.
Phone number is I user.
City is s user.
Address is s user.
User date is ordered.
It is is this.
So one, two, three, four, five, six, seven.
And then comma, and then we need to pass the parameters in order.
So the first or the first parameter is the order cost.
The second is the order.
The second is the order status.
The third is the user I.D..
The fourth is the phone number is the user form.
Which is fine here.
I just say it's fun.
And then.
After the phone.
We have this very.
And after the city, we have the address and the candidates address.
And repeat order.
However.
Order.
It.
However, I forgot the email.
So the email, the email is not yours.
So we need to insert the email or we can just rely on the phone number.
So I think I'm going to rely on the phone number.
You can rely on the phone number or you can use the user ID to get the user to get the phone number
from the from the user's database.
So there is no problem.
I'm not going to use the email.
So the email, I'm just going to get the email and leave it here.
There's no need to use the email because we have a phone number and we have the user ID where we can
use to get more information of the user later if we want to.
Next I'm going to say is the empty and then execute.
That's it.
We need to execute this query.
And lastly, we need to get the order item.
So this is going to insert this order into the database.
And the database in return is going to issue a new order.
Therefore, we need to get this we need to get this order ID in order to use it later in the script.
So we need to get the user ID from here.