Hello and welcome to the simulation, and you are going to handle that BHP HTP request or post.
They are going to create a new script.
So let's go back here.
And click tools go to your file manager, and this is the place where you can upload files.
You can click here and start uploading files to your website.
As you can see, go here, the five measure, and once you are in this window, in this section, we
are going to create a BHB script that is responsible for receiving incoming requests from the E.S.P
32 ball.
And it will be also responsible for inserting the data into my actual database, the one that we just
created here.
And if you are using a hosting provider with a panel like this one, you can simply navigate to the
file manager the way I did then select public HDMI option.
Now, this fall, that Double-Click it once you are in this folder, click the plus sign and create
a new file.
Now it will ask you to name the new file.
So what you need to do is call it past data.
Not it will be abused BHP file and will post data to the ISP database, so click create.
This is our first BHB file now to enter this file and to enter your code, you can simply click on it
and click, I did sign.
Now you can write your HP code here and this window.
But first, let's write it on another editor, then we can copy and paste the code to this window.
Let's download the sublime text editor.
It's a very sophisticated text editor.
That you can use to write codes.
It will take a second to download, as you can see, it has a graphical and coloring.
Uh, you can easily write codes and it will complete autocomplete, the chords while you write and you
can search the code.
So I recommend that when you write any type of code, it supports almost all of the programming languages.
OK, that's it.
Now open the setup file, click, yes.
OK.
Next night.
That's it now go to the start menu, click sublime or sublime text.
Now, this is it, you can use the control button and the mouse scroll to increase the font size and
to choose the programming language that you are dealing with.
You can simply do that by going to get the view.
And from the syntax, you can check any programming language that you are going to write your code in.
And in our case, it will be PSP.
Now, the first thing that you need to do when you are creating a new HP file is right, HP, and you
need this is called the tag and you need to close it.
Once you created.
Now we need to pass the first variabilities surname.
And the civil name will be localhost just like an hour.
Text file with me, check.
OK, let me open up the text file and as you can see, use localhost as a connection hostname so the
server name will be localhost.
Now, the next step will be assigning the database name and username and password.
So the dollar sign and the B name until you need to pass the name.
And we also need to pass the username database username.
And the database pass.
And these values are going to get from the text file that we did use, this is the password and this
is the username.
And this is the database name.
Now, we usually have a prefix before this, but we will go back to that at the end of recording session.
Now, what we are doing is creating an API.
So we are going to create a special key that no one knows and use it for our API to allow connection
between E.S.P and our PSP or our website.
So.
Right, that sign and write API underscore key, underscore value and you can write any key value.
Let's copy this and paste it here and we are going to use the same code in our E.S.P coding process.
Just like we did in our password, we did copy and paste the password exactly the same as in our website.
So this will be a special key that will be used and ESB code.
Now, the API key will pass a few variables.
And these variables will be the central variable.
OK, let me know the dollar sign sensor.
And to give these variables, we need to go back to our.
Called Let me.
Open up the article at the.
As you can see, this is the code that we did.
Execute.
And we need to get the names from that, the table here, so we need the census data, we can copy it
from here and based it here, and we will also need the remaining variables.
So let's copy all of them and let's based them here.
OK, at a little sign, equal dollar sign for each one of these.
OK, now, baby, I will pass all of these variables and at the end add equal and let's pass them as
empty text.
Now we need to ask if there is a post request, and since most of you won't be familiar with HP, I
will play stuccoed and I'll explain it.
Now, as you can see here, here we have a statement, if the server received a post request, then
check the IP, if it matches the IP that we have here.
Which is this one then start taking values, as you can see here, we have the census data, which is
the first value on our table.
The second value is the table or the location data and the value one value to add value three plus the
reading time.
Now, the reading time will automatically be created by the server since we did.
Make it auto created and our actual query so we don't have to pass the I.D. or the reading time.
That's why we are only passing these values.
So these values, the ID and the reading time won't be passed because they will be automatically created
by our website once it receives a new data.
So it will name one and will find the time, then it will write down these values that it did receive
from the ISP.
But this is the call to check the post request now to create a connection for the database.
We need to use this code, as you can see, this is a variable called KCON from Connection, and it's
creating a new object from the my actual data database object, and it's taking server name, username,
password and database name.
These values are installed here, as you can see.
So if any of these values is wrong, there will be no connection with the database.
So if you did pass the right values, the connection would be established.
Otherwise it will print out connection failed.
As you can see in this message now, moving on, after creating a connection with the database, we
need to start passing the values now to start passing the values of the database.
We need to use the insert, let's insert command.
And as you can see, the answer to insert these values that since the location, the value on value
to add value three, which are basically these values that the take from this.
A connection, so the values will be written and this actual query will be executed, which will basically
insert these values into the table, and we are going to create another BHP file to display these values.
But for now, this is basically an actual query that passes the values of the sense or location, value
and value to and value free.
Now, the next step will be to check if a new record was successfully created in our database or not
after we passed these values.
So to do that, what we need to do is check with an if statement.
This statement will ask if there is a connection to the Ezekial and if it is true, it means that new
record was created successfully.
If there is any problem that won't be created and will print out an error.
You don't have to memorize any of these things.
You just need to copy and paste, but you have to know what you are copying and pasting.
Now, once you are done.
With the query, you need to close the connection, so.
We will close the connection using connection, close method, otherwise we need to equal that, we
have received a strong API key.
So if the insert didn't work and we didn't get the data, this means that the API key that we did receive.
Is wrong, and in that case, it won't allow us to take the or and location and value data so it will
print out wrong Iraqi provided and this is for debugging purpose.
You want to see it on the screen and I will show you how to see it in case there is any problem.
Now.
There is another scenario where no data is posted with a YouTube post, if the eSport is offline or
if it is not sending any data.
We have to print that.
No data was received to make sure that the user knows that we didn't get any data from the ECB board
and it's not an API key problem.
Now, that is a function that we can use, which is to test and board and to make sure that this input
is right.
Now, this function will test the input and make sure that the input was written correctly and was passed
correctly.
Now, as you can see that this input will take the data as input and will it will trim anything that
is not considered data, then it will make some adjustment and return the data that we need, which
is basically that since or the reading of the character.
So if there is any other space in the incoming data, it will remove it and it will remove and special
characters and pass only the values that we want.
And this function was called in our code here, as you can see.
So when we receive that API key, we are making sure that we receive the key without any spaces or any
special key that might be wrong or that might be passed in a wrong way.
So this is very important to pass this off, to use this function.
I will provide you with the full code so that you can copy and paste the code and you need to make sure
that you change these values depending on your code.
So change that ISP database, name ISP board and the password and the API key value, depending on your
readings so that this code can be usable for you.
That's it for this lesson.
Now, one last step is basically select the code, select all.
Kobe and go to your file manager based code and click Save.
As you can see, this is our code click, save and close.
Now you have this file with your code, but before saving the file, you need to make sure that you
did modify the database, name the username and password variables with your unique details after adding
database, name, username and password, save the file just like I did and continue with the court's
instruction.
If you try to access your domain name using this file, you can see the following result.
The first step is goal and could be your website.
You are, as you can see, this is your website.
You are now at Slash and you need to write the same name post data, DOT, PSP or post data dot BHP.
Now, as you can see now that are posted with HTP Post because we haven't yet posted any data.
If you did get this message, it means that you have done everything correctly and that you have write
your code correctly.
Now in the next class we are going to write a script to the Sibley database content, but that's it
for this lesson.
Thanks for watching.
If you have any questions, please ask in the Q&A about.