WEBVTT 00:00:06.630 --> 00:00:13.600 So now before we test our code we will need to link our javascript file to our PSP file. 00:00:13.830 --> 00:00:14.400 OK. 00:00:14.580 --> 00:00:22.430 So we're going to need to add a script elements. 00:00:25.180 --> 00:00:29.310 OK. 00:00:31.590 --> 00:00:41.780 With a source going to kill file those trace file. 00:00:42.230 --> 00:00:48.600 Right now let's save on have a quick look at our page to see if there are any other changes to be made 00:00:48.600 --> 00:00:48.990 . 00:00:49.080 --> 00:00:53.240 So you can see here that we're locked in. 00:00:53.250 --> 00:00:57.180 Ours is a name we supposed to see our actual username. 00:00:57.250 --> 00:00:57.710 OK. 00:00:57.870 --> 00:01:01.110 So we've done this with our main page 00:01:04.840 --> 00:01:07.840 file on our notes file. 00:01:07.850 --> 00:01:08.320 All right. 00:01:08.400 --> 00:01:11.000 So let's copy the code from there. 00:01:11.750 --> 00:01:12.300 So 00:01:15.630 --> 00:01:20.810 this is the code that needs to go in 00:01:35.390 --> 00:01:37.540 to control f and look for use in the 00:01:52.030 --> 00:01:53.740 fine fresh page now 00:01:58.510 --> 00:02:00.390 so we can see anything there. 00:02:00.600 --> 00:02:06.510 OK so this means that it didn't recognize the session user name so let's see if we start with a session 00:02:06.770 --> 00:02:11.550 at the beginning of page code. 00:02:12.570 --> 00:02:19.470 OK so this is a session right at the beginning. 00:02:19.950 --> 00:02:23.890 We can copy the code from our notes page. 00:02:24.270 --> 00:02:35.880 So we just a session and also if we don't find a session user ID we can redirect the user to the landing 00:02:35.880 --> 00:02:36.420 page. 00:02:36.570 --> 00:02:42.150 OK so let's copy this whole code right 00:02:45.840 --> 00:02:51.430 now and save and refresh. 00:02:51.780 --> 00:02:52.100 OK. 00:02:52.170 --> 00:02:55.510 So you can see the correct use any. 00:02:55.730 --> 00:02:57.230 All right. 00:02:57.540 --> 00:02:57.830 All right. 00:02:57.840 --> 00:03:01.160 Now it works but we're going to have a problem later on. 00:03:01.170 --> 00:03:09.640 So the reason why is because the value we used here is the value that we had in the session array. 00:03:09.990 --> 00:03:10.480 OK. 00:03:10.560 --> 00:03:19.020 So let's say that we update our username if you update the user name the user name is going to get updated 00:03:19.350 --> 00:03:21.390 in the Users table. 00:03:21.870 --> 00:03:28.180 But you're still going to be using the same value which you stored in the session array. 00:03:28.200 --> 00:03:28.510 OK. 00:03:28.530 --> 00:03:30.160 Which is the old value. 00:03:31.140 --> 00:03:38.840 So to avoid this we're not going to use the value we have in our session array. 00:03:38.940 --> 00:03:44.110 We're going to go to the users table and retrieve the user name from that. 00:03:44.600 --> 00:03:45.540 OK. 00:03:46.290 --> 00:03:55.350 And then we're going to use that username as we find to fill this username. 00:03:55.830 --> 00:03:58.100 OK so how are we going to do this. 00:03:58.380 --> 00:04:11.460 Basically in this BHB code OK we're going to retrieve the username from our users table. 00:04:11.700 --> 00:04:12.330 OK. 00:04:12.330 --> 00:04:21.940 So to do this we're going to K'NEX first to the database including our connection file. 00:04:25.110 --> 00:04:28.520 OK. 00:04:30.930 --> 00:04:42.420 And then we're going to need to run a query which will get our user name from this table so we cannot 00:04:43.110 --> 00:04:44.920 use the user ID. 00:04:45.210 --> 00:04:45.960 OK. 00:04:45.990 --> 00:04:47.220 To get the user name. 00:04:47.580 --> 00:04:56.160 If you remember we stored the user id in the session array and that user ID is not going to change during 00:04:56.160 --> 00:04:57.730 the whole session of this user. 00:04:57.840 --> 00:04:59.760 So we can use it for this purpose. 00:05:00.000 --> 00:05:00.950 OK. 00:05:01.350 --> 00:05:06.860 So the story is inside a variable user ID so you going to get it from the session array 00:05:11.930 --> 00:05:15.660 so we use the key user id like this. 00:05:16.310 --> 00:05:25.350 OK so now let's get our using the we can get the e-mail as well. 00:05:25.560 --> 00:05:27.390 OK. 00:05:28.120 --> 00:05:32.270 Which we'll use later on for the e-mail code. 00:05:32.260 --> 00:05:38.700 So let's get them both to save time. 00:05:40.920 --> 00:05:46.970 All right so our queries going to be to select 00:05:51.230 --> 00:05:59.430 records from our table uses where the user ID is one 00:06:01.010 --> 00:06:06.380 . 00:06:10.190 --> 00:06:12.170 OK. 00:06:13.940 --> 00:06:21.500 Now I store the results inside the results variable. 00:06:26.260 --> 00:06:32.650 So the Maia's go like wearie function again will take the link variable where we store our connection 00:06:32.890 --> 00:06:36.620 and are clearly right. 00:06:37.360 --> 00:06:38.190 All right. 00:06:38.190 --> 00:06:45.200 Now we know that there is only one record in our users table with the user ID. 00:06:45.800 --> 00:06:52.780 But still we're going to check how many rows Okay we've got inside that's a result variable. 00:06:52.780 --> 00:06:58.590 So we're going to define a variable counts. 00:06:58.610 --> 00:06:59.250 OK. 00:06:59.770 --> 00:07:04.140 Well we're going to store the number of rows so to get the number of rows it's my is choli 00:07:07.010 --> 00:07:13.070 and the school number of rows and it's going to take as a barometer 00:07:15.640 --> 00:07:18.500 our result variable. 00:07:19.490 --> 00:07:21.850 OK. 00:07:24.250 --> 00:07:31.010 So now we're going to check if the number of rows is one to know if count 00:07:33.740 --> 00:07:40.880 is 1 then we're going to fetch the only row we've got. 00:07:40.940 --> 00:07:42.770 OK. 00:07:42.760 --> 00:07:47.490 And we're going to store that row inside a variable that we're going to call. 00:07:48.760 --> 00:07:49.670 All right. 00:07:50.360 --> 00:07:56.060 So if hetero's we're going to use the function my as choli fetch array. 00:07:56.350 --> 00:07:56.740 OK. 00:07:56.790 --> 00:07:58.940 So you must know this one you've done it many times. 00:07:59.090 --> 00:08:03.950 So the promises are going to be our results very well. 00:08:04.380 --> 00:08:05.540 OK. 00:08:05.620 --> 00:08:08.900 And you can add an optional parameter. 00:08:09.040 --> 00:08:10.830 So let's go for. 00:08:10.970 --> 00:08:12.590 And as you've array. 00:08:12.740 --> 00:08:20.150 So for this we're going to use my Esquivel my school and the school. 00:08:20.410 --> 00:08:21.940 All right. 00:08:24.070 --> 00:08:26.850 OK so now we've got our own ero. 00:08:26.940 --> 00:08:27.610 OK. 00:08:27.620 --> 00:08:29.920 So it's a guess the user name from last row. 00:08:30.110 --> 00:08:31.890 Let's define a variable. 00:08:31.900 --> 00:08:33.110 Use a name. 00:08:34.310 --> 00:08:39.850 And we're going to access the user name using the key username. 00:08:40.180 --> 00:08:46.480 OK this corresponds to the same name of our column. 00:08:46.610 --> 00:08:47.210 OK. 00:08:47.480 --> 00:08:51.190 And who gets the e-mail. 00:08:51.620 --> 00:08:54.460 We're going to do the same thing. 00:08:56.340 --> 00:09:00.310 Now we're going to use the key e-mail. 00:09:01.150 --> 00:09:03.960 OK. 00:09:06.280 --> 00:09:08.060 All right. 00:09:09.060 --> 00:09:17.220 If the count is not equal to 1 then we're going to echo an error message. 00:09:17.840 --> 00:09:21.650 Well if the code is written correctly you're not supposed to get this. 00:09:21.710 --> 00:09:22.370 OK. 00:09:22.400 --> 00:09:27.740 Going to write it just in case so there was an error. 00:09:29.590 --> 00:09:31.750 OK. 00:09:31.850 --> 00:09:43.690 Retrieving the user name and email from the database. 00:09:43.690 --> 00:09:52.390 OK so let's save this now to show the user name right there right there and right there we're going 00:09:52.390 --> 00:09:54.450 to use our user name variable. 00:09:54.640 --> 00:09:55.610 Very easy. 00:09:56.090 --> 00:09:56.360 OK 00:09:56.360 --> 00:10:05.780 . 00:10:05.770 --> 00:10:06.500 So we're going to 00:10:09.520 --> 00:10:10.370 change this 00:10:16.790 --> 00:10:18.940 to username. 00:10:20.250 --> 00:10:21.720 OK. 00:10:21.960 --> 00:10:22.600 Also 00:10:25.550 --> 00:10:31.260 we're going to go to our table and change this value to the user name variable 00:10:37.940 --> 00:10:51.310 . 00:10:59.200 --> 00:11:03.920 And finally in sight our form need to do as well 00:11:03.930 --> 00:11:10.910 . 00:11:18.740 --> 00:11:24.110 So it's instead of value we're going to echo. 00:11:24.150 --> 00:11:24.550 Use the 00:11:53.410 --> 00:11:56.700 game make sure you don't use this semi-colon. 00:11:56.750 --> 00:11:57.140 OK 00:12:03.860 --> 00:12:13.260 . 00:12:23.590 --> 00:12:31.180 All right so it's save and refresh. 00:12:32.240 --> 00:12:34.510 OK so you can see the Carex you the name. 00:12:34.550 --> 00:12:39.430 Now let's change our user name. 00:12:43.240 --> 00:12:44.340 OK. 00:12:45.160 --> 00:12:46.470 And submits. 00:12:47.380 --> 00:12:47.710 OK. 00:12:47.710 --> 00:12:50.920 And you can see the new username OK updated. 00:12:50.950 --> 00:12:58.970 And if you check inside our table we need to see the new use any and that's great because then you use 00:12:58.960 --> 00:12:59.530 a name. 00:12:59.680 --> 00:13:00.730 OK. 00:13:00.830 --> 00:13:04.630 All right so in the next video we're going to move to the password. 00:13:04.730 --> 00:13:04.990 OK. 00:13:05.000 --> 00:13:08.090 We leave the e-mail till the end gets more complicated. 00:13:08.300 --> 00:13:10.990 So we are going to do the code which will change the password