WEBVTT 00:05.380 --> 00:09.820 Now we going to check if there are any errors in that case we're going to print an error message. 00:09.820 --> 00:16.420 Otherwise we're going to create a query run the query and check if the query has been successful. 00:16.420 --> 00:20.600 If it's not successful then we're going to show an error message again. 00:20.600 --> 00:21.080 All right. 00:21.400 --> 00:32.680 So now let's check if there is an error in print an error message. 00:32.990 --> 00:38.150 So there is an error if the error is variable is not empty. 00:38.210 --> 00:42.550 You can just check that like this. 00:42.610 --> 00:50.790 So if that's the case then we're going to place all those paragraphs as we did inside the errors variable 00:50.790 --> 00:55.410 we're going to play them inside a div and at some signing to that. 00:55.540 --> 01:02.660 So this creates a variable results message. 01:04.140 --> 01:10.990 It's going to be a div and then inside a div we can replace paragraphs. 01:11.370 --> 01:13.310 OK this time it looks odd. 01:13.330 --> 01:21.800 A couple of glosses may actually use single quotes inside because I'm using the Alcoa's outside so I'm 01:21.810 --> 01:26.530 going to add the alerts clause and the alert danger clause. 01:26.530 --> 01:27.230 All right. 01:27.370 --> 01:37.050 So then we're going to echo this verbal. 01:37.190 --> 01:40.770 So once we do that that means that the file is returning something. 01:40.790 --> 01:48.400 And when we go back to the AJAX call then that's going to be true. 01:48.530 --> 01:55.920 OK and this means that we're going to show the error message inside the street message. 01:56.140 --> 02:01.960 Right now we're going to have an else statements meaning that we have no errors. 02:02.380 --> 02:14.250 So first of all if we have no errors we are going to prepare our valuables to the query. 02:14.610 --> 02:20.730 So the variables really need to prepare for the query are merely the departure and destination everything 02:20.760 --> 02:21.370 else. 02:21.390 --> 02:25.430 We actually don't need to prepared for the query because we checked. 02:25.520 --> 02:26.750 This is only digits. 02:27.000 --> 02:27.540 OK. 02:27.540 --> 02:34.980 Both the price and the seats and everything else is quite straightforward. 02:34.980 --> 02:36.640 These are fully checked. 02:36.720 --> 02:39.470 OK so the values are well known for us. 02:39.480 --> 02:44.040 These are also checks so there is nothing that the user is going to type manually. 02:44.240 --> 02:44.710 OK. 02:44.820 --> 02:49.690 Apart from these two and we have you checked that there are only digits in sight. 02:50.050 --> 02:50.670 OK. 02:50.700 --> 02:56.410 So the only ones we're going to be checking are the departure and destination. 02:56.400 --> 02:56.670 So 03:00.410 --> 03:07.410 we going to go to the departure variable and replace its by 03:10.160 --> 03:11.530 the prepared version. 03:11.620 --> 03:21.020 Going to use the function is choli and the score reel escape strength which will take a couple of promises. 03:21.170 --> 03:25.900 The connection variable and the old departure. 03:26.240 --> 03:31.290 OK so now our departure is prepared for the query we're going to do the same thing for the destination 03:33.630 --> 03:34.400 let us know. 03:34.430 --> 03:36.120 Prepared for the query. 03:36.120 --> 03:43.330 Now before we run the query we're going to check if we have a regular trip or a one off trip. 03:43.340 --> 03:45.950 So for each case we're going to have a different query. 03:46.250 --> 03:47.870 So it's starts with the regular case 03:56.460 --> 04:10.220 so the regular case means does the value of regular is why OK then we're going to have a query for a 04:10.220 --> 04:12.810 regular trip. 04:12.970 --> 04:20.160 Else we're going to have a query for a one off trip. 04:21.390 --> 04:27.280 OK so let's define the table name. 04:39.200 --> 04:40.550 Because this is how I'm going to use 04:43.390 --> 04:49.930 capital and the come case great so 04:56.180 --> 05:06.800 a table is called contra Costa Tripps. 05:08.000 --> 05:08.580 OK. 05:08.690 --> 05:14.190 So let's create the query and then placing inside a variable as well. 05:14.870 --> 05:22.580 So what we're going to be doing here we're going to insert a new record inside our table. 05:22.780 --> 05:23.610 All right. 05:23.900 --> 05:30.060 So we're going to take all the inputs of the user for a regular trip. 05:30.320 --> 05:41.830 So that means all these ones plus the regular radio button the weekdays and the time so 05:45.280 --> 05:50.580 we're going to insert into table 05:58.560 --> 06:02.070 so we're going to specify here the columns that we're going to be setting into. 06:02.100 --> 06:08.340 They're going to have the vollies straight after. 06:08.380 --> 06:12.340 All right so let's start with the columns. 06:13.720 --> 06:16.030 So are we going to start with the user id 06:47.340 --> 06:50.350 OK then the departure 06:53.290 --> 07:00.670 then departure longitude departure lassitude 07:03.080 --> 07:03.670 situation 07:08.980 --> 07:12.870 and the price then seats available 07:16.720 --> 07:20.620 and the regular. 07:21.530 --> 07:24.540 Okay they're going to have all the week days. 07:24.590 --> 07:24.890 Okay. 07:24.890 --> 07:28.520 Because we have a regular case here and then the time. 07:28.940 --> 07:29.220 Okay. 07:29.240 --> 07:33.770 Now the values are going to be the corresponding bodies for all of these. 07:33.770 --> 07:38.950 So the user ID is the user OK be connected to user. 07:39.020 --> 07:47.180 So we can get the user id from the session variables which define a variable user id just access user 07:47.180 --> 07:48.560 ID from the session 07:59.930 --> 08:04.800 as the user id The departure is going to be one. 08:06.110 --> 08:07.220 And then the departure 08:09.580 --> 08:11.080 longitude and latitude 08:23.840 --> 08:27.490 is make where you follow the right order here and then the destination 08:30.960 --> 08:32.090 then the situation 08:37.840 --> 08:39.010 and then the price 08:47.560 --> 08:48.440 seats available 08:54.670 --> 08:55.690 then regular 09:04.820 --> 09:08.030 and then the weekdays Okay. 09:08.030 --> 09:09.920 So we are going to have each one of these 09:16.560 --> 09:17.250 and then the time 09:22.670 --> 09:25.020 and of because all our values. 09:25.200 --> 09:26.570 All right. 09:27.250 --> 09:35.240 So thats our query for a regulatory query for a one off trip is more or less similar. 09:35.680 --> 09:36.570 OK. 09:36.730 --> 09:39.100 So we are just going to remove all the weekdays 09:44.080 --> 09:47.230 and we're going to replace them with the date 10:11.860 --> 10:21.600 right now are we going to run the query and saw the results in side results very well again going to 10:21.600 --> 10:32.190 use the My Lai query function which takes the connection link connection variable the query promises. 10:32.210 --> 10:34.440 So now we're going to check if the query is successful 10:39.920 --> 10:44.880 so I'm going to check if it's not successful it's going to take the opposite of results. 10:51.130 --> 10:54.090 If that's the case we're going to echo an error message 11:04.090 --> 11:09.080 saying something like there was an error. 11:09.790 --> 11:11.290 The trip could not be added 11:14.650 --> 11:25.890 to the database and it's odd because that's less danger clauses. 11:26.890 --> 11:33.070 OK so it's save before we move on let's just have a quick look at code and make sure that everything 11:33.070 --> 11:33.790 is OK. 11:34.030 --> 11:44.070 I can see something that the price is outside the quotes. 11:44.720 --> 11:49.220 And also if I just go back to the break much function 11:52.150 --> 11:56.500 the price needs to be inside that function as well. 11:58.070 --> 11:59.140 Like that. 11:59.920 --> 12:02.320 And when you do the same thing. 12:02.810 --> 12:03.960 Are the seats available 12:10.520 --> 12:11.140 Okay. 12:11.380 --> 12:14.270 So that's save. 12:15.600 --> 12:20.000 Okay I've got another one in this line. 12:20.040 --> 12:22.240 It's on extra and. 12:22.480 --> 12:23.050 Okay. 12:23.170 --> 12:26.960 You don't need that right now Lister's. 12:26.980 --> 12:28.060 Okay. 12:29.230 --> 12:34.990 So the stores I'm going to submit an empty form just to make sure that we get the right error messages. 12:35.390 --> 12:35.940 Okay. 12:36.190 --> 12:44.200 So unexpected we can see the error messages corresponding to missing departure destination price seats 12:44.200 --> 12:46.290 available and frequency. 12:46.300 --> 12:54.320 So if we select the frequency we don't see any weak days and we don't see any time OK. 12:54.320 --> 12:55.110 That's correct. 12:59.050 --> 12:59.680 Perfect 13:02.720 --> 13:03.330 Okay. 13:09.210 --> 13:13.170 All right it puts a wrong of the situation 13:16.960 --> 13:18.290 Perfect's. 13:18.530 --> 13:24.040 So let's try a one off trip without a date. 13:25.970 --> 13:27.680 Great I. 13:27.700 --> 13:46.730 So now let's try something with Carex data. 13:46.900 --> 13:49.790 So it's a mix 13:57.600 --> 14:01.470 of a quick look at our table. 14:01.540 --> 14:03.250 OK so we've got one record there. 14:03.550 --> 14:09.340 Okay so call the departure from very lean going to what we call the longitude and latitude longitude 14:09.340 --> 14:10.930 of the departure. 14:10.930 --> 14:15.180 Same for the destination Okay. 14:15.210 --> 14:20.320 We can see the dates and time as well. 14:21.780 --> 14:26.020 So it works destroy another one 14:41.070 --> 14:47.340 the price slightly and let's make this one day regular just testing 14:51.450 --> 14:52.020 Okay. 14:52.100 --> 14:58.730 So it's created a triple so nobody would need to hide the model. 14:58.730 --> 14:59.640 We haven't done that yet. 14:59.760 --> 15:00.300 OK. 15:00.470 --> 15:06.640 So we just want to check now table and make sure that everything works OK and we call the New York. 15:06.660 --> 15:09.240 There you go the right user id 15:13.690 --> 15:14.700 say I regret a trip. 15:14.790 --> 15:18.100 So I say why. 15:18.250 --> 15:20.060 It's Monday on Tuesday 15:23.780 --> 15:25.290 and the time ok. 15:25.310 --> 15:31.280 Going to say it was all OK perfect so our code works. 15:31.360 --> 15:31.670 All right. 15:31.680 --> 15:37.690 Now let's go back to our jobs because while it does make sure that we hide the model once we submit 15:37.690 --> 15:38.960 the form and everything is OK. 15:39.090 --> 15:44.160 And also we need to make sure this week empty the error Dave. 15:44.280 --> 15:44.760 OK. 15:44.820 --> 15:54.480 If everything is successful and also we go into resets of form once we submit the form. 15:54.750 --> 15:59.550 So we were supposed to do all of this right there. 15:59.610 --> 16:10.170 So to hide the model we're going to select the module using its ID so the ID of the model was 16:13.550 --> 16:14.380 Trip model 16:17.920 --> 16:18.780 Okay. 16:19.000 --> 16:28.020 So to hide these We're going to use the module method and I'm going to give it a barometer height. 16:28.030 --> 16:37.720 We're going to recess the form we're going to select the form using its ID. 16:37.750 --> 16:41.160 So the idea of the form was chip form 16:43.920 --> 16:47.340 to hide it or to reset it. 16:47.400 --> 16:51.850 We're going to need to use the reset method but we can't use it straight away. 16:51.870 --> 16:55.920 We need to go to the elements of index 0 first. 16:55.920 --> 16:57.040 OK. 16:57.130 --> 17:05.370 So it's a bit different than using the elements by ID which we can use trace with javascript's. 17:05.520 --> 17:06.340 But since we're using. 17:06.330 --> 17:13.200 Querrey that's the correct way of using the reset method like that's OK. 17:13.510 --> 17:18.830 And then finally to load the trips we're going to need to define a function. 17:18.940 --> 17:23.350 I'm going to call it gets Tripps OK. 17:24.360 --> 17:28.730 But for now we haven't defined the function yet. 17:29.010 --> 17:39.380 OK so we're going to need to come back to this function later and define it here just to avoid any errors. 17:39.570 --> 17:43.710 It's going to define an empty function for now. 17:44.540 --> 17:48.110 So we're going to use this function right there. 17:48.140 --> 17:51.130 And also we're going to use it when we load the page. 17:51.170 --> 17:52.100 OK. 17:52.550 --> 17:57.720 From scratch. 17:57.740 --> 18:05.380 All right so let's save and try our code again OK before I move on. 18:05.400 --> 18:09.230 I'm going to change the title of this page to my trips instead of my notes. 18:10.680 --> 18:12.120 That's better. 18:18.410 --> 18:20.960 OK so you're ready to test this code. 18:21.040 --> 18:25.420 So it's refreshed the page. 18:25.590 --> 18:27.730 A new trip. 18:28.820 --> 18:30.120 Let's try something. 18:39.250 --> 18:40.070 OK. 18:44.490 --> 18:46.150 So let's make it a one off 18:53.500 --> 18:55.650 so our model disappeared. 18:55.880 --> 18:59.650 And if I open the model again I can see that the form has been reset. 18:59.820 --> 19:01.200 Right. 19:01.330 --> 19:08.130 So now let's have a look at the database and see if you call. 19:08.170 --> 19:13.160 And you recall there perfect unexpected and. 19:13.200 --> 19:14.490 Everything is fine. 19:14.580 --> 19:17.600 I got all our data in there. 19:17.870 --> 19:19.260 All right. 19:19.350 --> 19:24.650 In the next video we're going to create the gatekeepers function which will send an area school to the 19:24.660 --> 19:29.030 get troops file and retrieve all the trips from the database.