WEBVTT 00:00:08.010 --> 00:00:13.680 So first we're going to get the user id which will store inside the user id variable. 00:00:13.680 --> 00:00:16.380 So again you're going to go to the session array 00:00:20.550 --> 00:00:20.970 and 00:00:23.520 --> 00:00:27.100 use the key user ID. 00:00:27.910 --> 00:00:36.100 OK then we're going to get the time as the current time we're going to use the time function. 00:00:37.770 --> 00:00:42.240 And then we going to run a query which will create a new note. 00:00:42.390 --> 00:00:44.240 So the query is going to be hours following. 00:00:44.240 --> 00:00:49.440 So we are inserting a new note in the notes table. 00:00:49.560 --> 00:00:54.830 So insert into the notes table. 00:00:56.040 --> 00:00:57.180 So we're going to specify 00:01:00.450 --> 00:01:08.950 the columns first and then we're going to specify the values that we would like to insert in those calls 00:01:08.960 --> 00:01:09.530 . 00:01:10.620 --> 00:01:15.430 So it starts with the columns. 00:01:16.650 --> 00:01:24.220 So we're going to have the user id note and type. 00:01:24.600 --> 00:01:24.900 OK 00:01:24.900 --> 00:01:42.070 . 00:01:45.180 --> 00:01:45.550 All right. 00:01:45.570 --> 00:01:48.750 And then the values are going to be following. 00:01:48.750 --> 00:01:52.210 So for the user id we're going to use our user id variable. 00:01:52.590 --> 00:01:53.400 OK. 00:01:53.790 --> 00:01:57.480 Then the news is going to be empty. 00:01:57.480 --> 00:02:04.510 So in the notes column we're going to have empty content. 00:02:04.680 --> 00:02:10.510 And then for a time we're going to use the time variable. 00:02:10.770 --> 00:02:13.390 Make sure you don't forget the single quotes. 00:02:13.410 --> 00:02:24.650 OK so now we're going to execute our query and so the results in the results very well done before so 00:02:24.660 --> 00:02:31.410 we're going to use the function of my is choli and the underscore query and I'm going to use the link 00:02:31.740 --> 00:02:33.050 variable. 00:02:33.150 --> 00:02:34.690 On the query. 00:02:35.310 --> 00:02:39.630 OK then we're going to check if 00:02:42.450 --> 00:02:44.780 the query was successful. 00:02:45.170 --> 00:02:48.060 OK if it was not successful 00:02:50.760 --> 00:02:53.570 we're going to look at the opposite of results. 00:02:53.740 --> 00:02:57.440 If it's not successful he's also going to be false and it's going to be true. 00:02:57.450 --> 00:03:02.980 So in that case we're going to return error in to our AJAX call. 00:03:03.060 --> 00:03:05.640 So we're going to echo Tara. 00:03:06.650 --> 00:03:07.510 All right. 00:03:07.830 --> 00:03:18.740 Then if everything goes fine and the query is successful we're going to return the ID of the unit. 00:03:18.860 --> 00:03:25.290 So there is a function as we used before which will return the auto generated ID OK used in the last 00:03:25.290 --> 00:03:26.060 query. 00:03:26.090 --> 00:03:29.260 Now its function is my is choli 00:03:31.960 --> 00:03:33.330 insert ID. 00:03:33.710 --> 00:03:34.620 Okay. 00:03:34.620 --> 00:03:38.670 So we are going to echo this. 00:03:38.880 --> 00:03:42.530 So this function will take as a barometer our link variable. 00:03:42.890 --> 00:03:44.550 Okay. 00:03:44.700 --> 00:03:49.710 So going to play I'm going to write the comments so. 00:03:51.450 --> 00:04:02.670 So this function is going to return the auto generated Id use in the last query. 00:04:03.200 --> 00:04:05.660 Okay the last query is this one. 00:04:05.850 --> 00:04:06.390 Okay. 00:04:06.390 --> 00:04:12.850 So you going to get the ID of the newly inserted note. 00:04:12.870 --> 00:04:16.500 All right so before we test our code I'm going to make a couple of changes. 00:04:16.500 --> 00:04:25.800 So there is an as missing from values you know a query and also in the jobs case file in the four statements 00:04:26.070 --> 00:04:28.760 we need to use semi-colons. 00:04:28.910 --> 00:04:30.900 I think instead of Commerce 00:04:35.790 --> 00:04:37.080 here we go. 00:04:37.080 --> 00:04:42.310 So now let's save our code and refresh the page. 00:04:43.260 --> 00:04:52.550 So now if I click on the odd notice button we can see the X area appearing and our button all notes 00:04:52.640 --> 00:04:54.330 OK now. 00:04:54.420 --> 00:04:59.520 Now let's have a look at our table and see if you cause a new record. 00:04:59.550 --> 00:05:05.060 So as refresh and we can see on your record write that. 00:05:05.130 --> 00:05:06.850 So our notes is empty. 00:05:06.930 --> 00:05:07.760 OK. 00:05:08.130 --> 00:05:10.940 Cause it didn't have any content there. 00:05:11.010 --> 00:05:11.930 All right. 00:05:11.970 --> 00:05:13.050 Now let's test 00:05:17.010 --> 00:05:18.790 our alerts. 00:05:18.900 --> 00:05:19.650 Message. 00:05:19.800 --> 00:05:32.080 OK so if we go back to the PSP file and make something or make an error in a query that's the ones we 00:05:32.080 --> 00:05:36.880 get. 00:05:36.880 --> 00:05:38.970 So you can see our message there. 00:05:39.190 --> 00:05:43.490 OK so it's a colossal collapsable LS message and we can close it. 00:05:43.570 --> 00:05:45.430 OK. 00:05:46.600 --> 00:05:53.770 Now let's try again with a correct one and make sure everything works perfect. 00:05:54.210 --> 00:05:54.520 All right. 00:05:54.520 --> 00:06:05.140 Now if we go back to our ADX goals just as we used a success barometer we need to use an Arab promise 00:06:05.140 --> 00:06:05.900 as well. 00:06:06.180 --> 00:06:06.700 OK. 00:06:07.030 --> 00:06:07.330 So 00:06:10.690 --> 00:06:18.910 we need to on an era of promiser in our first age ex-school as well as in our second one. 00:06:18.940 --> 00:06:25.340 So the era of Prometa corresponds to the age ex-school failing on going through. 00:06:25.630 --> 00:06:26.160 OK. 00:06:26.530 --> 00:06:30.640 So we're going to define a function OK 00:06:34.150 --> 00:06:35.480 which will show. 00:06:35.570 --> 00:06:42.430 And the last message all we going to do is place contents in the same collapsable LS message and just 00:06:42.700 --> 00:06:49.320 showing the message using some animation so we can use the same content we used right here. 00:06:49.760 --> 00:06:51.230 Okay. 00:06:52.990 --> 00:06:57.520 And just change the contents of the message saying something like there was 00:07:00.280 --> 00:07:04.600 an error with the AJAX call. 00:07:05.350 --> 00:07:05.830 OK. 00:07:05.860 --> 00:07:10.150 Please try again. 00:07:10.200 --> 00:07:11.090 All right. 00:07:11.450 --> 00:07:12.910 And we need to do the same thing 00:07:19.090 --> 00:07:21.960 here. 00:07:24.580 --> 00:07:24.970 OK 00:07:25.430 --> 00:07:40.490 . 00:07:50.320 --> 00:07:51.240 OK. 00:07:52.690 --> 00:08:00.600 We can try the AJAX call failing by giving the wrong place profile for example. 00:08:00.660 --> 00:08:04.540 It's very free reload the page you can see the Ajax. 00:08:04.540 --> 00:08:07.500 Well you can see the error corresponding to the AJAX call failing. 00:08:07.600 --> 00:08:12.410 OK. 00:08:12.580 --> 00:08:15.250 All right. 00:08:15.780 --> 00:08:23.500 Now if we look at the final up if we click on Add notes we can see the text area and we all knew it 00:08:23.520 --> 00:08:24.150 wasn't. 00:08:24.490 --> 00:08:30.330 So you can either start typing the notes or go back to the list of notes by clicking on the notes button 00:08:30.340 --> 00:08:31.340 . 00:08:31.390 --> 00:08:36.790 So let's write some code that will enable the user to click on this button and go back to the list of 00:08:36.790 --> 00:08:37.670 notes. 00:08:38.140 --> 00:08:46.260 So we're going to go to this section OK. 00:08:46.990 --> 00:08:54.400 So we're going to access the button using its ID so the ID of this button if you remember is on notes 00:08:54.420 --> 00:08:58.900 . 00:09:03.540 --> 00:09:04.230 OK. 00:09:04.750 --> 00:09:12.470 So once we click on this button we're going to execute the following function. 00:09:12.490 --> 00:09:20.770 So basically what we're going to be doing is we're going to load the notes as we did earlier when the 00:09:20.770 --> 00:09:22.430 page was loaded. 00:09:22.690 --> 00:09:23.230 OK. 00:09:23.650 --> 00:09:28.850 So we're going to use more or less the same code we used right there. 00:09:28.960 --> 00:09:30.570 OK for the AJAX call. 00:09:31.000 --> 00:09:37.610 So let's copy paste does good. 00:09:41.290 --> 00:09:41.590 OK 00:09:41.590 --> 00:09:48.340 . 00:09:48.340 --> 00:09:56.800 The only thing that's going to change is that when you click on that button you want to hide these two 00:09:56.800 --> 00:09:59.490 elements and show all those elements. 00:09:59.620 --> 00:10:00.160 OK. 00:10:00.160 --> 00:10:06.490 So we're going to use the hide function inside the success promiser. 00:10:07.330 --> 00:10:07.840 OK. 00:10:07.960 --> 00:10:08.530 So we're going to 00:10:17.710 --> 00:10:18.980 show some elements. 00:10:19.030 --> 00:10:20.380 Hide seven elements 00:10:20.400 --> 00:10:27.450 . 00:10:34.630 --> 00:10:40.140 OK so the elements we're going to show are going to be the notes in 00:10:44.470 --> 00:10:54.640 the eddies and the notes on the elements to hide going to be the all notes in 00:10:59.380 --> 00:11:01.400 the text area. 00:11:01.540 --> 00:11:02.210 OK. 00:11:02.560 --> 00:11:04.180 Which corresponds to the elements of ID. 00:11:04.190 --> 00:11:07.850 Notepad and exits. 00:11:08.560 --> 00:11:09.200 OK. 00:11:09.550 --> 00:11:14.890 So let's save and try our code. 00:11:16.440 --> 00:11:16.960 OK. 00:11:17.080 --> 00:11:19.670 It works perfectly. 00:11:19.780 --> 00:11:29.170 So at the moment when we create the new notes the empty notes and then we click on that and we don't 00:11:29.170 --> 00:11:35.260 see any empty notes and the reason why is because if you remember when we loaded the notes in the low 00:11:35.260 --> 00:11:39.190 notes file we deleted all empty notes. 00:11:39.220 --> 00:11:40.220 OK. 00:11:40.930 --> 00:11:41.770 All right. 00:11:42.160 --> 00:11:53.860 So in the next video we're going to write code which will save any updates to the new notes once we 00:11:53.860 --> 00:11:55.450 start typing the units. 00:11:55.450 --> 00:11:56.250 OK. 00:11:56.410 --> 00:12:01.970 And this will apply also when editing an existing note