WEBVTT 00:00:07.680 --> 00:00:13.200 Now we're going to check if there are any errors which means that our error is variable is not empty 00:00:13.200 --> 00:00:13.590 . 00:00:13.590 --> 00:00:20.330 So let's make comments here. 00:00:21.850 --> 00:00:25.510 So if there are any errors we're going to print an error 00:00:31.390 --> 00:00:36.460 so we're going to check if the error is variable is not empty. 00:00:36.560 --> 00:00:36.950 OK. 00:00:37.150 --> 00:00:38.890 Like this. 00:00:38.940 --> 00:00:39.900 So if that's the case 00:00:42.780 --> 00:00:47.630 we're going to create a variable is call it results message. 00:00:48.510 --> 00:00:52.160 OK. 00:00:54.690 --> 00:00:59.480 So this variable is going to contain our errors very well with some decoration. 00:00:59.490 --> 00:01:01.650 So this creates a div. 00:01:02.120 --> 00:01:02.390 OK 00:01:05.510 --> 00:01:11.430 . 00:01:16.440 --> 00:01:22.740 Let's give it a class. 00:01:22.860 --> 00:01:24.000 And as Dana 00:01:28.040 --> 00:01:29.190 all points and 00:01:32.850 --> 00:01:38.390 misplace the error is variable inside. 00:01:39.850 --> 00:01:41.430 OK. 00:01:43.230 --> 00:01:47.640 So we're going to echo this variable. 00:01:47.760 --> 00:01:48.720 OK. 00:01:49.350 --> 00:01:51.050 If there are any errors. 00:01:51.480 --> 00:01:53.690 OK now before we move on let's see if I. 00:01:53.700 --> 00:01:54.760 A couple of things. 00:01:54.780 --> 00:02:00.540 So if you look at the different than sign as you of course here the exclamation mark needs to be attached 00:02:00.540 --> 00:02:01.960 to the equals signs. 00:02:02.170 --> 00:02:03.230 OK. 00:02:03.240 --> 00:02:11.400 Also when I copied the connection code to the connection file I left this girl is in here pay the leases 00:02:11.850 --> 00:02:13.770 and we're going to need to. 00:02:13.970 --> 00:02:23.690 It's the end of this file save there and OK. 00:02:24.890 --> 00:02:27.860 Save them. 00:02:27.860 --> 00:02:28.110 All right. 00:02:28.110 --> 00:02:33.480 Now let's test our code and see how the output looks like with the set function. 00:02:33.660 --> 00:02:36.740 OK so let's refresh the page. 00:02:37.060 --> 00:02:39.710 OK now let's submit an empty form. 00:02:40.380 --> 00:02:46.540 OK so you were expecting to get error messages asking the user to provide the missing fields but instead 00:02:46.590 --> 00:02:52.020 we want the next step in our code and we started checking the validity of the e-mail address and the 00:02:52.020 --> 00:02:52.850 password. 00:02:53.190 --> 00:02:57.750 So the reason why we're guessing this is because we're using the function is set the function is set 00:02:57.750 --> 00:03:02.820 is going to be positive as far as you providing a field. 00:03:02.910 --> 00:03:03.470 OK. 00:03:03.570 --> 00:03:06.230 Even if that field is empty. 00:03:06.750 --> 00:03:11.030 So in our case the user name is actually there but it's empty. 00:03:11.220 --> 00:03:11.970 OK. 00:03:12.210 --> 00:03:18.330 So instead of using the said function we're going to use another function which is going to check if 00:03:18.570 --> 00:03:21.630 the field is empty or not. 00:03:21.630 --> 00:03:25.020 Rather than checking that the field is submitted. 00:03:25.410 --> 00:03:28.670 So the function is set. 00:03:28.890 --> 00:03:30.110 OK. 00:03:30.330 --> 00:03:36.140 Is going to be replaced by the function is not empty. 00:03:36.210 --> 00:03:37.020 OK. 00:03:37.020 --> 00:03:41.760 All the opposites of it sets is going to be replaced by the function empty. 00:03:42.000 --> 00:03:42.720 OK. 00:03:42.900 --> 00:03:45.410 By the way we don't have the function is not empty. 00:03:46.170 --> 00:03:49.620 OK but empty is the opposite of is not empty 00:03:49.640 --> 00:03:58.530 . 00:04:07.770 --> 00:04:08.320 OK. 00:04:08.580 --> 00:04:11.820 Now it is save and refresh the page again. 00:04:11.820 --> 00:04:13.790 Now let's submit an empty form again. 00:04:14.130 --> 00:04:17.270 And now we are getting the error messages that we were expecting. 00:04:17.430 --> 00:04:20.640 OK so we see that's the user name is missing. 00:04:20.700 --> 00:04:24.710 And we were asked to enter using name same for the e-mail address and the password. 00:04:24.780 --> 00:04:28.360 Ok then I will provide a username. 00:04:29.720 --> 00:04:30.490 OK. 00:04:30.490 --> 00:04:33.380 We've got only a couple of messages for the e-mail and password. 00:04:33.460 --> 00:04:38.110 Now provide only the first password. 00:04:39.690 --> 00:04:43.020 OK so we're not verifying the requirements or the password. 00:04:43.140 --> 00:04:46.680 OK so let's provide a good password with the right requirements 00:04:52.250 --> 00:04:54.910 Well right now we need to confirm the password. 00:04:55.020 --> 00:04:57.930 Let's give a different password. 00:04:59.050 --> 00:04:59.690 OK. 00:04:59.950 --> 00:05:06.750 Now our error our errors work OK and we get the right error messages. 00:05:06.840 --> 00:05:07.680 OK. 00:05:08.380 --> 00:05:11.820 Now let's move to the next step. 00:05:11.960 --> 00:05:12.490 OK. 00:05:12.840 --> 00:05:15.050 And see where you're going to do. 00:05:15.210 --> 00:05:17.700 If we don't have any errors. 00:05:17.700 --> 00:05:18.410 All right. 00:05:18.570 --> 00:05:24.240 So if you don't have any errors we're going to prepare variables for the queries. 00:05:24.250 --> 00:05:30.070 This means that we're going to clean our variables before we put them inside any query to avoid any 00:05:30.060 --> 00:05:31.300 Escorial injection. 00:05:31.310 --> 00:05:37.730 OK so the variables are going to prepare are going to be the user name email address and password. 00:05:37.880 --> 00:05:38.390 OK. 00:05:38.740 --> 00:05:42.900 So now we got no errors. 00:05:43.750 --> 00:05:45.630 OK. 00:05:46.160 --> 00:05:52.670 I'm going to prepare the variables for the queries. 00:05:54.120 --> 00:05:56.940 OK so the first variable is going to be the username. 00:05:57.270 --> 00:06:03.930 OK so we're going to go inside the variable user name the clean version of the variable. 00:06:03.940 --> 00:06:06.270 Use a name that we created before. 00:06:06.560 --> 00:06:06.990 OK. 00:06:07.100 --> 00:06:09.560 Well he's going to be this one. 00:06:09.990 --> 00:06:10.530 OK. 00:06:10.890 --> 00:06:20.790 So to do that we're going to use the function my Eskew ly real escape strings. 00:06:21.250 --> 00:06:22.070 OK. 00:06:23.070 --> 00:06:28.620 We have covered this before in the contact form products. 00:06:28.830 --> 00:06:29.940 OK. 00:06:30.890 --> 00:06:34.720 All right so this is going to take a couple of pharmacists are the first barometer is going to be the 00:06:34.710 --> 00:06:39.400 variable where we saw our connection in our case it's link. 00:06:41.010 --> 00:06:48.040 And the second Damita is the variable to clean which is usually OK. 00:06:48.180 --> 00:06:52.860 So you're going to do the same thing with the email and password 00:06:52.880 --> 00:07:03.550 . 00:07:13.510 --> 00:07:14.370 OK. 00:07:14.740 --> 00:07:20.670 Now for the password we're going to need to encrypt our password as we are not going to be able to store 00:07:20.700 --> 00:07:22.990 our put password like this in plaintext. 00:07:23.070 --> 00:07:23.990 OK. 00:07:24.030 --> 00:07:32.520 That's not the good practice we always need to encrypt passwords using a strong encrypted Ohashi function 00:07:32.520 --> 00:07:32.610 . 00:07:32.620 --> 00:07:32.980 OK. 00:07:33.120 --> 00:07:35.370 I'm going to come back to the password in a bit. 00:07:35.380 --> 00:07:36.340 All right. 00:07:36.880 --> 00:07:42.340 Now we're going to check if the user name provided by the user is already really set in our database 00:07:42.330 --> 00:07:42.600 . 00:07:42.610 --> 00:07:43.190 OK. 00:07:43.690 --> 00:07:48.370 So there's going to be the first set. 00:07:49.250 --> 00:07:50.020 Right. 00:07:50.190 --> 00:07:53.630 So to do this we're going to create a query. 00:07:54.030 --> 00:07:54.640 OK. 00:07:54.630 --> 00:07:58.220 We're going to squeeze in the variable that's going to go as well. 00:07:58.720 --> 00:08:00.660 So the query is going to be us following. 00:08:00.660 --> 00:08:04.920 So we're going to selects all the records. 00:08:05.150 --> 00:08:06.300 Okay. 00:08:06.420 --> 00:08:10.280 From our users table. 00:08:10.360 --> 00:08:13.950 So the name of the table is going to go inside single quotes 00:08:17.160 --> 00:08:21.120 . 00:08:23.400 --> 00:08:28.160 The condition is going to be where the username 00:08:31.240 --> 00:08:36.140 is equal to the value provided by our user. 00:08:36.270 --> 00:08:36.710 OK. 00:08:36.850 --> 00:08:40.320 So that value is the variable used in it. 00:08:40.500 --> 00:08:42.920 Okay. 00:08:44.500 --> 00:08:50.500 So since we are using double quotes for our strength we can place the variable use the name like that's 00:08:51.250 --> 00:08:53.340 straight away inside a string. 00:08:53.620 --> 00:08:57.100 Okay. 00:08:57.730 --> 00:08:59.020 So that's our query. 00:08:59.040 --> 00:09:05.140 Now we are going to need to run the query so to run the query we're going to use the function might 00:09:05.620 --> 00:09:11.490 as clearly underscore query which will take a couple of promises. 00:09:11.630 --> 00:09:12.300 Okay. 00:09:12.310 --> 00:09:18.280 So again the first parameter is our link variable where we saw the connection and the second variable 00:09:18.340 --> 00:09:20.250 is the query itself. 00:09:20.950 --> 00:09:21.500 Okay. 00:09:21.510 --> 00:09:26.770 And then we're going to going to store the results in slide a very well are we going to call it results 00:09:26.870 --> 00:09:29.080 . 00:09:29.120 --> 00:09:29.490 Right. 00:09:29.500 --> 00:09:33.000 So now we run the query. 00:09:33.420 --> 00:09:35.990 Now let's check if the query is successful. 00:09:36.100 --> 00:09:36.730 Okay. 00:09:36.720 --> 00:09:43.260 So if the query is not successful the results of the function my school-I query is going to be false 00:09:43.260 --> 00:09:43.500 . 00:09:43.570 --> 00:09:46.230 Okay otherwise we're going to get an object. 00:09:46.600 --> 00:09:50.710 So to check if the query is not successful. 00:09:51.470 --> 00:09:53.120 Okay. 00:09:56.480 --> 00:10:02.020 We're going to check the opposite of results. 00:10:02.030 --> 00:10:05.130 OK. 00:10:06.770 --> 00:10:12.920 So if results is false this is going to be true which means the query is not successful in that case 00:10:12.920 --> 00:10:15.510 we're going to echo an error message. 00:10:15.880 --> 00:10:17.810 OK. 00:10:19.610 --> 00:10:24.190 So for example we can have a div 00:10:27.140 --> 00:10:34.350 K saying something like Error running the query. 00:10:34.520 --> 00:10:37.100 OK. 00:10:37.720 --> 00:10:44.030 All I would recommend you always check that's the query has run successfully before you check the results 00:10:44.030 --> 00:10:45.100 inside the query. 00:10:45.110 --> 00:10:45.580 OK. 00:10:45.800 --> 00:10:46.960 That's really important. 00:10:47.210 --> 00:10:49.180 OK and let's style it Dave. 00:10:49.240 --> 00:10:52.900 Give Wikipedia's a class. 00:10:53.360 --> 00:10:58.660 So it is give it a class let's Alessandra. 00:10:59.790 --> 00:11:02.020 OK. 00:11:02.370 --> 00:11:04.220 All right. 00:11:04.640 --> 00:11:10.470 Also once we echoed the error we can access the whole code using the exit function. 00:11:10.480 --> 00:11:11.380 OK. 00:11:12.350 --> 00:11:15.800 As we don't need to move to the remaining of the code. 00:11:15.980 --> 00:11:16.620 OK. 00:11:17.000 --> 00:11:23.610 Only one comments would need to place the value of the username in our query. 00:11:23.900 --> 00:11:27.090 Inside single quotes just like this. 00:11:27.790 --> 00:11:29.170 OK. 00:11:30.170 --> 00:11:32.240 All right. 00:11:32.240 --> 00:11:38.420 Now if the query is successful we're going to check how many records we've got in the results of our 00:11:38.420 --> 00:11:39.140 query. 00:11:39.260 --> 00:11:46.600 So to do this we're going to use a function called my is Kulai number of rows. 00:11:46.880 --> 00:11:47.820 OK. 00:11:48.320 --> 00:11:52.170 So this function is going to take the results object. 00:11:52.270 --> 00:11:53.430 OK. 00:11:54.090 --> 00:11:57.130 Here's the result of our Gary. 00:11:57.290 --> 00:11:57.850 OK. 00:11:58.190 --> 00:12:05.100 And let's talk this inside another variable and let's call these variable results. 00:12:05.120 --> 00:12:06.830 OK. 00:12:08.570 --> 00:12:08.840 So 00:12:13.610 --> 00:12:19.280 now we're going to check if the results is different than 0. 00:12:19.280 --> 00:12:19.820 OK. 00:12:19.970 --> 00:12:24.960 So to do is we can just place the results in the condition of the if statements. 00:12:25.240 --> 00:12:26.170 OK. 00:12:26.930 --> 00:12:27.810 Just like this. 00:12:28.040 --> 00:12:28.490 OK. 00:12:28.670 --> 00:12:32.660 So this is going to be true if it's different than zero. 00:12:32.720 --> 00:12:35.840 So if that's the case we're going to 00:12:38.750 --> 00:12:40.060 add to the errors 00:12:43.350 --> 00:12:46.800 variable. 00:12:48.200 --> 00:12:54.470 Another paragraph or this Aiko directly an error. 00:12:54.770 --> 00:12:55.050 Ok 00:13:02.690 --> 00:13:03.290 as a 00:13:06.300 --> 00:13:20.010 reason why something in a div like that is a name he's already really said you want to log in. 00:13:21.450 --> 00:13:35.910 OK let's decrease our day of using a class let's And let's change. 00:13:39.250 --> 00:13:42.550 OK. 00:13:42.860 --> 00:13:46.690 Now we're going to we're going to check if the email exists. 00:13:46.730 --> 00:13:48.330 So you've got a couple of choices. 00:13:48.350 --> 00:13:50.540 Either you can xes the code here. 00:13:50.660 --> 00:13:51.010 OK. 00:13:51.020 --> 00:13:53.970 Right after the error. 00:13:54.320 --> 00:13:55.010 OK. 00:13:55.010 --> 00:13:58.180 Otherwise you can use the else statements. 00:13:58.490 --> 00:14:01.360 OK for following the if statements. 00:14:01.580 --> 00:14:02.140 OK. 00:14:02.360 --> 00:14:05.640 So I'm going to go for the exit option. 00:14:05.690 --> 00:14:14.840 Now we're going to check if the email is there then we're going to print an error if the e-mail exists 00:14:14.850 --> 00:14:15.200 . 00:14:15.560 --> 00:14:16.840 OK. 00:14:16.850 --> 00:14:23.910 So to do this we're going to create a query the same way we've done with the user name. 00:14:24.170 --> 00:14:25.390 OK. 00:14:25.610 --> 00:14:26.120 And then 00:14:29.000 --> 00:14:31.360 we're going to follow exactly the same steps. 00:14:31.400 --> 00:14:40.240 So we're just going to copy this code and then change it for the e-mail. 00:14:40.240 --> 00:14:50.840 All right so the query is going to be using the email rather than using the. 00:14:52.670 --> 00:14:56.240 OK. 00:14:58.280 --> 00:14:58.900 OK. 00:14:58.920 --> 00:15:09.340 And then the error message is going to be that email is already really said OK. 00:15:09.620 --> 00:15:14.990 So once all these steps have been successful you're going to move to the next one which is creating 00:15:15.020 --> 00:15:17.560 a unique activation code. 00:15:17.650 --> 00:15:18.100 OK. 00:15:18.230 --> 00:15:25.620 And then inserting those activation code in the Users table. 00:15:25.790 --> 00:15:26.380 OK. 00:15:26.580 --> 00:15:31.880 With the other user details we're going to do that in the next video