1
00:00:00,860 --> 00:00:08,900
Hello and welcome to this annual lesson, and the child is going to handle the PSP city request or post.

2
00:00:10,100 --> 00:00:13,250
Are going to create a new script.

3
00:00:14,250 --> 00:00:16,020
So let's go back here.

4
00:00:17,160 --> 00:00:20,580
And click tools and go to your file manager.

5
00:00:21,900 --> 00:00:26,190
And this is the place where you can upload files.

6
00:00:27,130 --> 00:00:32,860
You can click here and start uploading files to your website.

7
00:00:35,030 --> 00:00:43,010
As you can see, goal here, the five manager, and once you are in this window, in this section,

8
00:00:43,010 --> 00:00:50,060
we are going to create a BHP squib that is responsible for receiving incoming requests from the ESB

9
00:00:50,060 --> 00:00:58,220
32 ball, and it will be also responsible for inserting the data into my database, the one that we

10
00:00:58,220 --> 00:01:00,110
just created here.

11
00:01:01,810 --> 00:01:09,670
And if you are using a hosting provider oversight panel like this one, you can simply navigate to the

12
00:01:09,850 --> 00:01:15,010
file manager the way I did, then select public option.

13
00:01:17,040 --> 00:01:24,450
Now this fall, cricket, once you are in this folder, click the plus sign and create a new file.

14
00:01:24,930 --> 00:01:34,440
Now it will ask you to name the new file, so what you need to do is call it post data.

15
00:01:36,860 --> 00:01:38,040
Not PSV.

16
00:01:38,330 --> 00:01:44,630
It will be obvious obituary file and will post data to the ISP database.

17
00:01:45,080 --> 00:01:47,360
So click Create.

18
00:01:49,040 --> 00:01:55,160
This is our first P2P file now to edit this file and to enter your code.

19
00:01:55,550 --> 00:01:59,210
You can simply click on it and click the edit sign.

20
00:02:00,590 --> 00:02:03,980
Now you can write your HP code here and this window.

21
00:02:04,610 --> 00:02:08,510
But first, let's write it on another editorial.

22
00:02:08,510 --> 00:02:11,800
Then we can copy and paste the code to this window.

23
00:02:13,280 --> 00:02:18,770
Let's download the sublime text editor.

24
00:02:21,170 --> 00:02:23,390
It's a very sophisticated text editor.

25
00:02:25,500 --> 00:02:27,240
That you can use to write codes.

26
00:02:31,440 --> 00:02:39,630
It will take a second to download, as you can see, it has a graphical and coloring, uh, you can

27
00:02:39,630 --> 00:02:46,440
easily write codes and it will complete autocomplete the codes while you write and you can search the

28
00:02:46,440 --> 00:02:46,920
code.

29
00:02:48,900 --> 00:02:56,010
So I recommend that when you write any type of code, it supports almost all of the programming languages.

30
00:03:00,600 --> 00:03:01,070
OK.

31
00:03:01,110 --> 00:03:01,770
That's it.

32
00:03:01,980 --> 00:03:03,960
Now open the set up.

33
00:03:04,980 --> 00:03:05,400
Yes.

34
00:03:08,940 --> 00:03:10,690
Puck next night.

35
00:03:12,850 --> 00:03:13,400
That's it.

36
00:03:14,380 --> 00:03:19,540
Now go the Start menu, click sublime or sublime text.

37
00:03:22,220 --> 00:03:23,060
Now this is it.

38
00:03:23,900 --> 00:03:28,760
You can use the control button and thus Mouscron.

39
00:03:29,120 --> 00:03:34,760
So increase the font size and to choose the programming language that you are dealing with.

40
00:03:35,150 --> 00:03:42,670
You can simply do that by going to go to view and form of a syntax.

41
00:03:42,740 --> 00:03:48,110
You can't take any programming language that you are going to write your code in.

42
00:03:48,440 --> 00:03:50,420
And in our case, will be PSP.

43
00:03:52,070 --> 00:03:59,180
Now, the first thing that you need to do when you are creating an HP file is right BHP.

44
00:04:01,400 --> 00:04:05,870
And you need this is called the tag and you need to close it.

45
00:04:07,160 --> 00:04:08,330
Once you created.

46
00:04:10,180 --> 00:04:14,470
Now we need to pass the first variable, which is ServerName.

47
00:04:17,520 --> 00:04:23,490
And the several name will be localhost just like an art.

48
00:04:26,530 --> 00:04:30,360
Text file, let me check.

49
00:04:30,630 --> 00:04:39,700
OK, let me open up the text file and, as you can see, use localhost as a connection hostname.

50
00:04:39,820 --> 00:04:41,740
So the server name will be localhost.

51
00:04:42,730 --> 00:04:51,740
Now, the next step will be assigning the database name and username and password so that the last sign

52
00:04:51,910 --> 00:04:53,500
and the IDB name.

53
00:04:55,030 --> 00:04:56,680
And here you need to pass the name.

54
00:04:57,530 --> 00:05:03,580
And we also need to pass the user name database username.

55
00:05:08,290 --> 00:05:10,660
And the database passports.

56
00:05:17,730 --> 00:05:25,680
And these values are going to get from the text file that we did use.

57
00:05:25,800 --> 00:05:30,270
This is the password and this is the username.

58
00:05:32,440 --> 00:05:34,150
And this is the database name.

59
00:05:35,620 --> 00:05:42,430
Now we usually have a prefix before this, but we will go back to that at the end of coding session.

60
00:05:44,530 --> 00:05:54,010
Now what we are doing is creating an API, so we are going to create a special key that no one knows

61
00:05:54,400 --> 00:06:02,830
and use it for our API to allow connection between ESB and our PSP or our site.

62
00:06:03,490 --> 00:06:16,870
So ride that dollar sign and Android API underscores key underscore value and his we can't write any

63
00:06:16,870 --> 00:06:17,530
key value.

64
00:06:18,580 --> 00:06:24,310
Let's copy this and paste it to you, and we are going to use the same code.

65
00:06:25,330 --> 00:06:27,340
Yes, USP coding process.

66
00:06:28,430 --> 00:06:37,350
Just like we did in our password, we did copy and paste the password exactly the same as normal.

67
00:06:37,370 --> 00:06:37,760
Sorry.

68
00:06:38,150 --> 00:06:43,040
So this will be a special key that will be used in speech codes.

69
00:06:43,580 --> 00:06:48,650
Now the API key will pass a few variables.

70
00:06:52,720 --> 00:06:54,700
These variables will be of the central variable.

71
00:06:55,740 --> 00:07:03,580
OK, let me know the last time sensor and took of these variables, we need to go back to our.

72
00:07:05,460 --> 00:07:06,600
Called me.

73
00:07:09,390 --> 00:07:11,490
Open up a at database.

74
00:07:12,620 --> 00:07:15,050
As you can see, this is the code that we did.

75
00:07:16,110 --> 00:07:16,890
Execute.

76
00:07:18,220 --> 00:07:23,530
And we need to give the names from the the table here.

77
00:07:23,980 --> 00:07:25,460
So we need this sort of data.

78
00:07:25,480 --> 00:07:33,160
We can't copy it from here and based it here, and we will also need the remaining variables.

79
00:07:33,160 --> 00:07:39,160
So let's copy all of them and let's paste them here.

80
00:07:41,960 --> 00:07:47,120
They add a dollar sign equal and dollar sign for each one of these.

81
00:07:49,720 --> 00:07:51,170
OK, now, baby.

82
00:07:52,120 --> 00:08:01,120
Will pass all of these variables and other and equal, and let's pass them as empty text.

83
00:08:02,640 --> 00:08:07,140
Now we need to ask if there is a post request.

84
00:08:07,990 --> 00:08:15,090
And since most of you won't be familiar with BHP, I will post that code and I'll explain it.

85
00:08:16,940 --> 00:08:25,430
Now, as you can see here, here we have if statement, if the server received a post request, then

86
00:08:26,030 --> 00:08:30,230
check the API key if it matches the API key that we have here.

87
00:08:31,950 --> 00:08:39,450
Which is this one then start taking values, as you can see here, we have the sort of data which is

88
00:08:39,450 --> 00:08:41,940
the first value on our table.

89
00:08:42,090 --> 00:08:50,290
The second value is the table or the location data on the value one, value two and value three blustery

90
00:08:50,310 --> 00:08:50,820
the time.

91
00:08:51,150 --> 00:08:56,010
Now that is in time will automatically be created by the server since we did.

92
00:08:57,610 --> 00:09:00,360
Make it auto created.

93
00:09:00,790 --> 00:09:02,380
And I'll ask you, I'll query.

94
00:09:02,590 --> 00:09:07,150
So we don't have to bust the I.D. or the reading time.

95
00:09:07,660 --> 00:09:09,640
That's why we are only passing these values.

96
00:09:09,640 --> 00:09:14,160
So these values, the I.D. and the reading time won't be passed the court.

97
00:09:14,160 --> 00:09:20,410
They will be automatically created by our website once it receives a new data, so it will name it one

98
00:09:20,560 --> 00:09:27,550
and will by the time, then it will write down these values that it did receive from various people.

99
00:09:28,210 --> 00:09:35,910
This is the code to check the post request now to create a connection for the database.

100
00:09:39,930 --> 00:09:44,490
We need to use this court, as you can see, this is a variable called on from conviction.

101
00:09:44,970 --> 00:09:47,850
And it's creating a new object from that.

102
00:09:47,940 --> 00:09:56,520
My ask you, I'll let a base object and it's taking server name, username, password and database name.

103
00:09:56,970 --> 00:10:01,290
These values are installed here, as you can see.

104
00:10:02,220 --> 00:10:07,140
So if any of these values is wrong, there will be no connection with the database.

105
00:10:07,680 --> 00:10:11,610
So if you did pass the right values, the connection would be established.

106
00:10:12,090 --> 00:10:18,150
Otherwise, it will print out connection failed, as you can see in this message.

107
00:10:18,510 --> 00:10:25,080
Now, moving on after creating a connection with the database, we need to start passing the values

108
00:10:26,460 --> 00:10:30,150
now to stop passing the values of our database.

109
00:10:30,540 --> 00:10:39,000
We need tools that insert, let's say, insert command and as you can see, the inserted and said these

110
00:10:39,270 --> 00:10:46,800
values that since all the location, the value on value to and value three, which are basically these

111
00:10:47,340 --> 00:10:49,980
values that it did take from this.

112
00:10:51,290 --> 00:10:52,260
API connection.

113
00:10:52,740 --> 00:10:59,100
So the values will be written and this asexual query will be executed, which will basically insert

114
00:10:59,220 --> 00:11:08,160
these values and to the table and who are going to create another BHP file to display these values.

115
00:11:08,460 --> 00:11:14,790
But for now, this is basically not non-sexual query that passes the values of the sensor location,

116
00:11:15,840 --> 00:11:17,430
value and value to and value.

117
00:11:17,430 --> 00:11:17,700
Three.

118
00:11:18,120 --> 00:11:25,560
Now, the next step will be to check if annual record was successfully created in our database or not

119
00:11:25,980 --> 00:11:27,690
after we passed these values.

120
00:11:28,110 --> 00:11:32,430
So to do that, what we need to do is check with an if statement.

121
00:11:33,390 --> 00:11:41,580
This statement will ask if there is a connection to the school and if it is true, it means that new

122
00:11:41,580 --> 00:11:43,560
record was created successfully.

123
00:11:44,190 --> 00:11:50,550
If there is any problem that a code won't be created and will print out on error, you don't have to

124
00:11:50,550 --> 00:11:52,200
memorize any of these things.

125
00:11:52,200 --> 00:11:56,790
You just need to copy and paste, but you have to know what you are copying and pasting.

126
00:11:57,300 --> 00:11:58,290
Now, once you are done.

127
00:11:59,670 --> 00:12:04,560
With the query, you need to close the connection, so.

128
00:12:05,520 --> 00:12:14,460
We will close the connection using connection clause methods, otherwise we need to equal that we have

129
00:12:14,460 --> 00:12:17,280
received around API key.

130
00:12:18,120 --> 00:12:26,910
So if the insert didn't work and we didn't get the data, this means that the API key that we did receive.

131
00:12:28,190 --> 00:12:35,330
Is wrong, and in that case, it won't allow us to take the sensor and location and values data, so

132
00:12:35,540 --> 00:12:38,080
it will print out wrong key.

133
00:12:38,900 --> 00:12:45,200
Provided this is for debugging purposes, you won't see it on your screen and I will show you how to

134
00:12:45,200 --> 00:12:47,810
see it and case there is any problem.

135
00:12:48,530 --> 00:12:49,040
Now.

136
00:12:51,240 --> 00:12:56,520
That is another scenario where no data is posted with a TV boss.

137
00:12:56,940 --> 00:13:04,470
If the ISP board is offline or if it is not sending any data, we have to pretend that no data was received

138
00:13:04,830 --> 00:13:12,600
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

139
00:13:12,600 --> 00:13:13,110
problem.

140
00:13:14,100 --> 00:13:20,200
Now that is a function that we can use, which is to test and bot and to make sure that this and what

141
00:13:20,220 --> 00:13:20,730
is right.

142
00:13:22,500 --> 00:13:27,780
Now, this function will test the input and make sure that the input was written correctly and was passed

143
00:13:27,780 --> 00:13:28,350
correctly.

144
00:13:28,860 --> 00:13:35,700
Now, as you can see that this input will take the data as input and will it will trim anything that

145
00:13:35,820 --> 00:13:44,700
is not considered data, then it will make some adjustment and retain the data that we need, which

146
00:13:44,700 --> 00:13:47,940
is basically that since all the reading, all of the character.

147
00:13:48,420 --> 00:13:56,760
So if there is any other space and incoming data, it will remove it and it will remove a special characters

148
00:13:57,090 --> 00:13:59,370
and pass only the values that we want.

149
00:13:59,910 --> 00:14:03,090
And this function was called our code here.

150
00:14:03,120 --> 00:14:03,840
As you can see.

151
00:14:04,290 --> 00:14:10,920
So when we receive that API key, we are making sure that we receive the key without any spaces or any

152
00:14:11,520 --> 00:14:17,370
special key that might be wrong or that might be passed in a wrong way.

153
00:14:17,880 --> 00:14:22,950
So it's very important to pass this off to use this function.

154
00:14:23,550 --> 00:14:28,410
I would provide you with a full code so that you can copy and paste the code, and you need to make

155
00:14:28,410 --> 00:14:32,970
sure that you change these values depending on your code.

156
00:14:34,080 --> 00:14:42,570
So change that GSP database name, you know, sport and the password and the key value depending on

157
00:14:42,570 --> 00:14:45,600
your readings, so that this gold can be usable for you.

158
00:14:46,290 --> 00:14:47,820
That's it for this lesson.

159
00:14:47,850 --> 00:14:53,190
Now, one last tip is basically select the code, select all.

160
00:14:55,630 --> 00:15:02,740
Kobe and go to your file manager based the code and click Save.

161
00:15:04,920 --> 00:15:06,510
As you can see, this is our code.

162
00:15:06,870 --> 00:15:08,260
Click, save and close.

163
00:15:08,280 --> 00:15:11,550
Now you have this file with your code.

164
00:15:12,600 --> 00:15:18,150
But before saving the file, you need to make sure that you did modify the database name that username

165
00:15:18,150 --> 00:15:25,560
and password variables with your unique details after adding database, name, username and password.

166
00:15:25,890 --> 00:15:34,290
Save the file just like I did and continue with the course instruction if you try to access your domain

167
00:15:34,290 --> 00:15:36,990
name using this file.

168
00:15:37,470 --> 00:15:40,140
You can see the following result.

169
00:15:41,400 --> 00:15:45,690
The first step is goal and copy your website.

170
00:15:46,200 --> 00:15:46,890
You are all.

171
00:15:47,700 --> 00:15:49,290
As you can see, this is your website.

172
00:15:49,290 --> 00:15:58,230
You are now at Slash and you need to have the same name post data dot PSP.

173
00:15:58,350 --> 00:16:00,690
So post that data.

174
00:16:01,050 --> 00:16:10,140
The BHP now, as you can see, know that are posted with each CTB post because we haven't yet posted

175
00:16:10,140 --> 00:16:11,070
any data.

176
00:16:11,370 --> 00:16:16,470
If you did give this message, it means that you have done everything correctly and that you have write

177
00:16:16,980 --> 00:16:18,060
your code correctly.

178
00:16:18,300 --> 00:16:26,070
Now, in the next lesson, we are going to write a BHP script to the Sibley database content, but that's

179
00:16:26,070 --> 00:16:26,940
it for this lesson.

180
00:16:27,210 --> 00:16:27,920
Thanks for watching.

181
00:16:27,930 --> 00:16:30,840
If you have any questions, please ask in the Q&amp;A about.
