Hello and welcome to this annual lesson, and the child is going to handle the PSP city request or post.
Are going to create a new script.
So let's go back here.
And click tools and 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, goal here, the five manager, and once you are in this window, in this section,
we are going to create a BHP squib that is responsible for receiving incoming requests from the ESB
32 ball, and it will be also responsible for inserting the data into my database, the one that we
just created here.
And if you are using a hosting provider oversight panel like this one, you can simply navigate to the
file manager the way I did, then select public option.
Now this fall, cricket, 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 post data.
Not PSV.
It will be obvious obituary file and will post data to the ISP database.
So click Create.
This is our first P2P file now to edit this file and to enter your code.
You can simply click on it and click the edit sign.
Now you can write your HP code here and this window.
But first, let's write it on another editorial.
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 codes 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 set up.
Yes.
Puck next night.
That's it.
Now go the Start menu, click sublime or sublime text.
Now this is it.
You can use the control button and thus Mouscron.
So increase the font size and to choose the programming language that you are dealing with.
You can simply do that by going to go to view and form of a syntax.
You can't take any programming language that you are going to write your code in.
And in our case, will be PSP.
Now, the first thing that you need to do when you are creating an HP file is right BHP.
And you need this is called the tag and you need to close it.
Once you created.
Now we need to pass the first variable, which is ServerName.
And the several name will be localhost just like an art.
Text file, let 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 that the last sign
and the IDB name.
And here you need to pass the name.
And we also need to pass the user name database username.
And the database passports.
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 coding 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 ESB and our PSP or our site.
So ride that dollar sign and Android API underscores key underscore value and his we can't write any
key value.
Let's copy this and paste it to you, and we are going to use the same code.
Yes, USP coding process.
Just like we did in our password, we did copy and paste the password exactly the same as normal.
Sorry.
So this will be a special key that will be used in speech codes.
Now the API key will pass a few variables.
These variables will be of the central variable.
OK, let me know the last time sensor and took of these variables, we need to go back to our.
Called me.
Open up a at database.
As you can see, this is the code that we did.
Execute.
And we need to give the names from the the table here.
So we need this sort of data.
We can't 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 paste them here.
They add a dollar sign equal and dollar sign for each one of these.
OK, now, baby.
Will pass all of these variables and other and 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 BHP, I will post that code and I'll explain it.
Now, as you can see here, here we have if statement, if the server received a post request, then
check the API key if it matches the API key that we have here.
Which is this one then start taking values, as you can see here, we have the sort of data which is
the first value on our table.
The second value is the table or the location data on the value one, value two and value three blustery
the time.
Now that is in time will automatically be created by the server since we did.
Make it auto created.
And I'll ask you, I'll query.
So we don't have to bust the I.D. or the reading time.
That's why we are only passing these values.
So these values, the I.D. and the reading time won't be passed the court.
They will be automatically created by our website once it receives a new data, so it will name it one
and will by the time, then it will write down these values that it did receive from various people.
This is the code to check the post request now to create a connection for the database.
We need to use this court, as you can see, this is a variable called on from conviction.
And it's creating a new object from that.
My ask you, I'll let a base 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 stop passing the values of our database.
We need tools that insert, let's say, insert command and as you can see, the inserted and said these
values that since all the location, the value on value to and value three, which are basically these
values that it did take from this.
API connection.
So the values will be written and this asexual query will be executed, which will basically insert
these values and to the table and who are going to create another BHP file to display these values.
But for now, this is basically not non-sexual query that passes the values of the sensor location,
value and value to and value.
Three.
Now, the next step will be to check if annual 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 school and if it is true, it means that new
record was created successfully.
If there is any problem that a code won't be created and will print out on 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 clause methods, otherwise we need to equal that we have
received around 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 sensor and location and values data, so
it will print out wrong key.
Provided this is for debugging purposes, you won't see it on your screen and I will show you how to
see it and case there is any problem.
Now.
That is another scenario where no data is posted with a TV boss.
If the ISP board is offline or if it is not sending any data, we have to pretend that no data was received
to make sure that the user knows that we didn't get any data from the ISP bald and it's not an API key
problem.
Now that is a function that we can use, which is to test and bot and to make sure that this and what
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 retain the data that we need, which
is basically that since all the reading, all of the character.
So if there is any other space and incoming data, it will remove it and it will remove a special characters
and pass only the values that we want.
And this function was called 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 it's very important to pass this off to use this function.
I would provide you with a 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 GSP database name, you know, sport and the password and the key value depending on
your readings, so that this gold can be usable for you.
That's it for this lesson.
Now, one last tip is basically select the code, select all.
Kobe and go to your file manager based the 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 that 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 course instruction if you try to access your domain
name using this file.
You can see the following result.
The first step is goal and copy your website.
You are all.
As you can see, this is your website.
You are now at Slash and you need to have the same name post data dot PSP.
So post that data.
The BHP now, as you can see, know that are posted with each CTB post because we haven't yet posted
any data.
If you did give this message, it means that you have done everything correctly and that you have write
your code correctly.
Now, in the next lesson, we are going to write a BHP 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.