1 00:00:00,540 --> 00:00:01,200 Welcome back. 2 00:00:01,560 --> 00:00:03,900 Now it's time to work on placing an order. 3 00:00:04,230 --> 00:00:10,410 And placing an order is going to it's going to be a long process because you might think that the process 4 00:00:10,410 --> 00:00:13,890 is you're just storing user information in the database, and that's not correct. 5 00:00:14,400 --> 00:00:20,760 There are many, many ways in order to accomplish placing an order, eliminate break down the process 6 00:00:20,760 --> 00:00:22,830 into few steps so that you understand. 7 00:00:23,340 --> 00:00:32,610 So now the first step is that we need to open up the place, order that BGP Illini here, type the steps 8 00:00:32,610 --> 00:00:33,240 that we want. 9 00:00:33,570 --> 00:00:41,820 So the first step is that we need to get user info because of course in order to send the, the, the 10 00:00:42,300 --> 00:00:46,680 product to the user, we need their email, we need their city, we need their phone number, we need 11 00:00:46,680 --> 00:00:50,610 their address in order to send the package and products to them. 12 00:00:51,300 --> 00:00:54,720 The second step is that we need to store. 13 00:00:56,400 --> 00:01:01,980 You get user info and store store it in database. 14 00:01:02,490 --> 00:01:03,270 In database. 15 00:01:03,840 --> 00:01:11,250 The second step is that we need to store order information, order info, and to store the order information 16 00:01:11,340 --> 00:01:14,220 information in database database. 17 00:01:15,030 --> 00:01:17,220 We first need to get 18 00:01:19,830 --> 00:01:22,260 products from cards. 19 00:01:22,800 --> 00:01:24,390 So the second step is actually. 20 00:01:25,800 --> 00:01:29,760 The second step is to get products from so many years. 21 00:01:29,790 --> 00:01:31,260 Type one, I'm going to say one. 22 00:01:31,650 --> 00:01:35,910 The first step is to get user info and store it in database. 23 00:01:36,510 --> 00:01:37,740 The second step is to. 24 00:01:38,920 --> 00:01:42,650 Get products from carts from from the station. 25 00:01:42,670 --> 00:01:46,840 Actually bring me out of here at night. 26 00:01:47,980 --> 00:01:52,660 I'm going to say from station so that you don't forget that the information is in position. 27 00:01:54,380 --> 00:02:01,910 The third step is that we want to place store the ordering information in database. 28 00:02:02,270 --> 00:02:08,990 So after we get the the the products from the station, we need to take these products and store them 29 00:02:08,990 --> 00:02:13,320 in the database and issue a new a new order. 30 00:02:13,340 --> 00:02:19,250 So we need to get a new order in the order stable and we need to store each individual product in the 31 00:02:19,250 --> 00:02:20,240 order items. 32 00:02:20,930 --> 00:02:27,260 So, for example, if I let me go back to the home page and explain the process, for example, if I 33 00:02:27,260 --> 00:02:28,130 want to buy. 34 00:02:29,830 --> 00:02:31,120 If I want to buy. 35 00:02:32,520 --> 00:02:41,160 If I want to buy a pair of shoes and buy a bag, then each each one of these must be stored in the order 36 00:02:41,160 --> 00:02:41,700 items. 37 00:02:42,210 --> 00:02:44,460 But both of them. 38 00:02:44,880 --> 00:02:53,970 Both of these items will have one single order because they belong to the same to the same person who 39 00:02:53,970 --> 00:02:55,800 wants to buy these two. 40 00:02:56,190 --> 00:03:05,700 So these two items will have the same order ID, but they will be stored in the order item so that we 41 00:03:05,700 --> 00:03:08,400 know the items that the user wants to buy. 42 00:03:09,030 --> 00:03:13,200 So here the third step is to store order info in database. 43 00:03:14,160 --> 00:03:28,200 First I need to say here issue new order and store order info in database and finally store store each. 44 00:03:29,480 --> 00:03:35,930 Single item in order items database. 45 00:03:39,850 --> 00:03:48,880 And the last step is to remove every thing from car. 46 00:03:50,010 --> 00:03:50,610 And. 47 00:03:53,870 --> 00:03:56,540 And actually, this is the fifth step. 48 00:03:56,960 --> 00:04:04,640 And the sixth step is to tell the user or inform informed user that. 49 00:04:06,880 --> 00:04:07,330 Whether. 50 00:04:09,590 --> 00:04:10,130 Whether. 51 00:04:14,240 --> 00:04:17,810 Every scheme is. 52 00:04:20,570 --> 00:04:21,170 Fine. 53 00:04:21,170 --> 00:04:22,700 Or there there's a problem. 54 00:04:23,510 --> 00:04:24,320 There is. 55 00:04:26,730 --> 00:04:27,420 A problem. 56 00:04:29,000 --> 00:04:31,280 And if there is a problem, we need to tell them. 57 00:04:31,610 --> 00:04:36,010 If everything's fine, we need to remind them to continue. 58 00:04:36,380 --> 00:04:38,210 We need to take them to the payment page. 59 00:04:38,780 --> 00:04:40,460 So this is the last step. 60 00:04:40,820 --> 00:04:42,560 Let's start working on these steps. 61 00:04:42,560 --> 00:04:44,360 So let's start on the first step. 62 00:04:44,720 --> 00:04:48,680 So the first step is to get user info and store it in the database. 63 00:04:49,100 --> 00:04:51,470 So in order to get the user info, we need to. 64 00:04:52,490 --> 00:05:00,290 Head on over to the to the check out and get these fields from before. 65 00:05:00,890 --> 00:05:07,840 So here we have the the names, name, email, phone, city address and place order. 66 00:05:07,850 --> 00:05:12,400 So if the user clicks on place order, we need to get the name. 67 00:05:12,410 --> 00:05:22,520 I'm going to say name is equal to last name and then we need to get the email. 68 00:05:28,140 --> 00:05:29,790 And then we took get on. 69 00:05:39,730 --> 00:05:41,230 And then we need to get the. 70 00:05:43,260 --> 00:05:46,140 We need to get the phone and Siri and address. 71 00:05:46,190 --> 00:05:48,420 We have Siri and address Siri. 72 00:05:49,870 --> 00:05:50,320 First. 73 00:05:51,710 --> 00:05:52,130 City. 74 00:05:56,240 --> 00:05:57,890 And lastly, we need to get the Aussies. 75 00:06:00,600 --> 00:06:02,580 So the address is going to be your past. 76 00:06:04,660 --> 00:06:05,230 Address. 77 00:06:06,100 --> 00:06:06,580 That's it. 78 00:06:07,030 --> 00:06:07,450 Now. 79 00:06:08,530 --> 00:06:10,980 We want to insert this into the database. 80 00:06:10,990 --> 00:06:13,510 These are our values in the database. 81 00:06:13,510 --> 00:06:16,690 And to do this, we need to import the connection. 82 00:06:16,690 --> 00:06:21,310 Remember the connection class, the connection file, because the connection will allow us to connect 83 00:06:21,310 --> 00:06:21,880 to the database. 84 00:06:22,300 --> 00:06:23,760 So at the top here, I'm going to say. 85 00:06:25,210 --> 00:06:26,080 Include. 86 00:06:26,530 --> 00:06:29,470 And then since we are in the same file. 87 00:06:29,890 --> 00:06:34,840 Replace or replace order that BHP is in the same file as the connection. 88 00:06:35,110 --> 00:06:45,920 So we just need to say here connection, connection that BHP and before we forget we also need to say 89 00:06:45,940 --> 00:06:48,850 session start because I'm going to be using this session later. 90 00:06:49,570 --> 00:06:55,840 I don't want to forget because this is usually forgotten by so many developers. 91 00:06:56,710 --> 00:07:03,460 So after we have this, we need to use the remember every connection we have. 92 00:07:04,240 --> 00:07:11,500 Again, let me remind you that we have a variable called con, so we need to use this con here. 93 00:07:11,500 --> 00:07:14,380 I'm going to say con and then. 94 00:07:16,610 --> 00:07:19,550 Prepare and then we need to pass the statement. 95 00:07:19,560 --> 00:07:22,400 So the statement is insert, insert. 96 00:07:24,900 --> 00:07:33,210 Insert into into what we need to insert into the we need to insert into the. 97 00:07:34,800 --> 00:07:38,220 The orders when you transition to the orders table. 98 00:07:38,880 --> 00:07:42,480 So we need to insert into the order table here. 99 00:07:42,480 --> 00:07:45,300 We need to insert into the order symbol. 100 00:07:45,900 --> 00:07:47,520 I'm going to say insert into. 101 00:07:51,090 --> 00:07:51,590 Orders. 102 00:07:52,800 --> 00:07:53,850 And what do we want? 103 00:07:53,880 --> 00:07:54,260 Insert. 104 00:07:54,270 --> 00:07:55,140 We want to insert. 105 00:07:56,070 --> 00:08:05,850 The order cost, the status, the I.D., the user, all of these things except for the IDI they ordered. 106 00:08:05,850 --> 00:08:07,920 It will be given by the database automatically. 107 00:08:08,160 --> 00:08:09,780 So we need to start by the order cost. 108 00:08:10,440 --> 00:08:16,680 So the order cost, I'm going to say here, order underscore cost is the total amount and I'm going 109 00:08:16,680 --> 00:08:17,850 to get this shortly. 110 00:08:18,450 --> 00:08:20,490 The second thing that we need to insert. 111 00:08:21,660 --> 00:08:23,460 Is the order status. 112 00:08:23,460 --> 00:08:25,830 The order status is always going to be on hold. 113 00:08:26,820 --> 00:08:28,800 So I'm going to say order underscore status. 114 00:08:29,790 --> 00:08:30,990 The third thing is. 115 00:08:33,200 --> 00:08:36,270 The user ID, so we need to get the user I.D.. 116 00:08:36,290 --> 00:08:41,690 I'm going to say user underscore ID and then we need the. 117 00:08:44,440 --> 00:08:44,980 Fun. 118 00:08:45,700 --> 00:08:46,420 User fun. 119 00:08:51,680 --> 00:08:52,340 And then. 120 00:08:53,780 --> 00:08:55,490 Use our phone and then city. 121 00:09:01,360 --> 00:09:05,260 User Siri and then user address and order date. 122 00:09:06,570 --> 00:09:07,170 User. 123 00:09:09,120 --> 00:09:11,910 Address and then order. 124 00:09:14,450 --> 00:09:14,750 The. 125 00:09:17,110 --> 00:09:18,880 And then in a new line, I'm going to hear. 126 00:09:20,190 --> 00:09:21,120 You're in a new line. 127 00:09:21,120 --> 00:09:26,100 I'm going to add a new line and then I'm going to say values. 128 00:09:27,140 --> 00:09:28,040 Values. 129 00:09:29,950 --> 00:09:31,060 So what are the values? 130 00:09:32,410 --> 00:09:34,000 The values are first. 131 00:09:35,350 --> 00:09:36,460 For the order cost. 132 00:09:36,910 --> 00:09:38,610 We need to get the costs from decision. 133 00:09:39,250 --> 00:09:43,300 So what I'm going to do is that I'm going to say here order costs. 134 00:09:44,800 --> 00:09:47,740 And to get our conversation, we just need to say session. 135 00:09:50,130 --> 00:09:51,640 And then total. 136 00:09:51,690 --> 00:09:56,360 This is going to get the total from the session and then the order status. 137 00:09:56,370 --> 00:10:00,060 I'm going to say order underscore status. 138 00:10:00,540 --> 00:10:04,260 The order status is whether the order has been paid or not. 139 00:10:04,740 --> 00:10:07,470 If the order has been paid, then we need to. 140 00:10:08,560 --> 00:10:13,930 I say, but we will allow users to to place orders without paying. 141 00:10:13,930 --> 00:10:17,650 And then after the order has been placed, I'm going to allow users to pay. 142 00:10:18,190 --> 00:10:22,830 So I'm going to say here, the the initial value is always going to be on all. 143 00:10:23,580 --> 00:10:28,000 So enrolled means that the order has been placed but has not been paid. 144 00:10:29,410 --> 00:10:36,340 And then user I.D., the user I.D. I'm going to get the user I.D. later when I allow users to log in 145 00:10:36,340 --> 00:10:37,000 and register. 146 00:10:37,270 --> 00:10:44,650 But for now, the user I.D. is always going to be one just for the sake of testing the the user phone 147 00:10:44,650 --> 00:10:45,040 number. 148 00:10:45,040 --> 00:10:46,600 We have the phone number from the forum. 149 00:10:47,080 --> 00:10:48,910 We have the name and we have everything else. 150 00:10:50,070 --> 00:10:51,630 Lastly, we need the order date. 151 00:10:53,040 --> 00:10:56,720 So we need to see order underscore the. 152 00:10:58,900 --> 00:11:02,860 So the order date is going to be a date. 153 00:11:04,700 --> 00:11:05,750 The time. 154 00:11:07,860 --> 00:11:09,660 Let's use the time now. 155 00:11:11,810 --> 00:11:13,550 Or we can use the date function. 156 00:11:13,550 --> 00:11:15,020 We can use date y. 157 00:11:15,920 --> 00:11:23,660 Y is for the year month date and then our second our minutes seconds, which is which is this function. 158 00:11:24,020 --> 00:11:25,850 Now we can pass these into the values. 159 00:11:26,300 --> 00:11:27,800 So the first thing is the order. 160 00:11:28,130 --> 00:11:28,910 The order cost. 161 00:11:28,970 --> 00:11:31,160 So I'm going to say your order cost. 162 00:11:32,390 --> 00:11:34,190 However, this is not a good practice. 163 00:11:34,190 --> 00:11:36,080 We need to pass question mark. 164 00:11:36,080 --> 00:11:39,090 So we need to see how many question marks we need to pass. 165 00:11:39,110 --> 00:11:42,290 One, two, three, four. 166 00:11:43,490 --> 00:11:45,080 Five, six, seven. 167 00:11:45,080 --> 00:11:46,350 So we have seven inputs. 168 00:11:46,350 --> 00:11:48,020 So I'm going to say your question, mark. 169 00:11:48,020 --> 00:11:53,540 One, two, three, four, five, six, seven. 170 00:11:53,900 --> 00:11:57,710 And if you don't understand why I'm doing this, this is for the sake of protection. 171 00:11:58,160 --> 00:12:04,490 And you can take my course about beach protection and you will understand the reason behind this, because 172 00:12:04,490 --> 00:12:10,040 this is going to protect the the form and it's going to protect your system from hackers. 173 00:12:10,520 --> 00:12:16,370 And again, if you want to take that course, I highly recommend taking that course about beach security 174 00:12:16,370 --> 00:12:17,240 best practices. 175 00:12:17,240 --> 00:12:26,660 If you are interested in understanding and improving your HB security code and applying best practices. 176 00:12:28,370 --> 00:12:30,860 Now we need to call a function here. 177 00:12:31,610 --> 00:12:35,390 We need to store this in a variable called is the empty. 178 00:12:37,190 --> 00:12:39,440 So esteem is going to be equal to conviction. 179 00:12:39,440 --> 00:12:41,120 Prepare and then. 180 00:12:42,780 --> 00:12:45,040 Is the empty. 181 00:12:45,930 --> 00:12:49,140 We need to call a function called buying program. 182 00:12:49,740 --> 00:12:52,780 And the parameters that I'm going to bind are the cost. 183 00:12:52,800 --> 00:12:55,560 So the cost is the cost here. 184 00:12:57,300 --> 00:13:00,450 The cost is integer I. 185 00:13:00,960 --> 00:13:03,210 And then the order status is going to be. 186 00:13:03,210 --> 00:13:07,600 Yes, string user ID is I is integer. 187 00:13:08,040 --> 00:13:11,370 Phone number is I user. 188 00:13:11,880 --> 00:13:15,570 City is s user. 189 00:13:15,570 --> 00:13:18,090 Address is s user. 190 00:13:20,370 --> 00:13:22,830 User date is ordered. 191 00:13:22,830 --> 00:13:24,300 It is is this. 192 00:13:24,820 --> 00:13:28,590 So one, two, three, four, five, six, seven. 193 00:13:30,030 --> 00:13:33,660 And then comma, and then we need to pass the parameters in order. 194 00:13:33,670 --> 00:13:37,170 So the first or the first parameter is the order cost. 195 00:13:37,740 --> 00:13:40,740 The second is the order. 196 00:13:42,400 --> 00:13:44,050 The second is the order status. 197 00:13:47,140 --> 00:13:49,860 The third is the user I.D.. 198 00:13:51,380 --> 00:13:55,670 The fourth is the phone number is the user form. 199 00:13:57,070 --> 00:13:58,230 Which is fine here. 200 00:13:58,240 --> 00:13:59,260 I just say it's fun. 201 00:14:00,100 --> 00:14:00,700 And then. 202 00:14:01,660 --> 00:14:02,470 After the phone. 203 00:14:02,470 --> 00:14:03,310 We have this very. 204 00:14:08,030 --> 00:14:12,650 And after the city, we have the address and the candidates address. 205 00:14:14,290 --> 00:14:16,570 And repeat order. 206 00:14:17,320 --> 00:14:17,980 However. 207 00:14:18,610 --> 00:14:19,300 Order. 208 00:14:21,990 --> 00:14:22,210 It. 209 00:14:22,710 --> 00:14:24,120 However, I forgot the email. 210 00:14:24,120 --> 00:14:27,780 So the email, the email is not yours. 211 00:14:27,800 --> 00:14:34,050 So we need to insert the email or we can just rely on the phone number. 212 00:14:34,530 --> 00:14:37,230 So I think I'm going to rely on the phone number. 213 00:14:39,490 --> 00:14:44,650 You can rely on the phone number or you can use the user ID to get the user to get the phone number 214 00:14:44,650 --> 00:14:47,320 from the from the user's database. 215 00:14:47,320 --> 00:14:48,340 So there is no problem. 216 00:14:48,760 --> 00:14:50,290 I'm not going to use the email. 217 00:14:50,290 --> 00:14:53,210 So the email, I'm just going to get the email and leave it here. 218 00:14:53,230 --> 00:14:58,660 There's no need to use the email because we have a phone number and we have the user ID where we can 219 00:14:58,660 --> 00:15:01,780 use to get more information of the user later if we want to. 220 00:15:02,530 --> 00:15:07,340 Next I'm going to say is the empty and then execute. 221 00:15:07,390 --> 00:15:07,800 That's it. 222 00:15:07,810 --> 00:15:09,070 We need to execute this query. 223 00:15:09,880 --> 00:15:13,150 And lastly, we need to get the order item. 224 00:15:13,480 --> 00:15:15,760 So this is going to insert this order into the database. 225 00:15:16,120 --> 00:15:20,380 And the database in return is going to issue a new order. 226 00:15:21,130 --> 00:15:27,190 Therefore, we need to get this we need to get this order ID in order to use it later in the script. 227 00:15:28,000 --> 00:15:31,120 So we need to get the user ID from here.