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