1 00:00:00,660 --> 00:00:01,290 Welcome back. 2 00:00:01,770 --> 00:00:07,470 The next step is, is that we need to get the products from the cart and insert each single product 3 00:00:07,470 --> 00:00:10,740 into the into the order items. 4 00:00:10,750 --> 00:00:19,080 So each single item we have will that the user box will be inserted individually into the into the database. 5 00:00:19,440 --> 00:00:25,500 So again, if the user, for example, wants to buy these, do we need to insert each one individually 6 00:00:25,500 --> 00:00:31,950 into in a separate raw in the database so that we know each item or which items the user wants. 7 00:00:32,610 --> 00:00:37,230 So here the second step first, before I move, before I work on the second step, I'm going to remove 8 00:00:37,230 --> 00:00:37,770 this echo. 9 00:00:38,970 --> 00:00:40,800 We know we no longer need this echo. 10 00:00:41,310 --> 00:00:44,160 So the second step is that we need to get products from the cart. 11 00:00:44,610 --> 00:00:50,280 So to get the products from the cart, we need to use the session because the decision has. 12 00:00:52,400 --> 00:00:56,630 The station has the card and this card is NRA. 13 00:00:57,180 --> 00:01:01,070 And since this card is NRA, it has the it has this structure. 14 00:01:01,070 --> 00:01:12,020 It has key value pair where each key represents a an order, represents a product ID and the value is 15 00:01:12,020 --> 00:01:14,810 an array with the information about that product. 16 00:01:15,410 --> 00:01:23,300 So for example, if we have two products in the card, the first key, the key is the product ID and 17 00:01:23,300 --> 00:01:28,220 the value is an array with product information such as the product price, the product name, the product 18 00:01:28,220 --> 00:01:31,460 product description. 19 00:01:32,660 --> 00:01:38,750 So what we want to do is that we need to use a for each loop in order to loop over for each in order 20 00:01:38,750 --> 00:01:47,060 to loop over the session and get each single product and store it in the into the order items database. 21 00:01:47,690 --> 00:01:52,190 So I'm going to say you for each and then for each white for each session. 22 00:01:53,690 --> 00:01:55,820 Garth, and I'm going to remove this. 23 00:01:55,820 --> 00:01:56,870 We no longer need this. 24 00:01:59,130 --> 00:02:05,370 So I'm going to thank you for each session card as he. 25 00:02:08,020 --> 00:02:08,680 Value. 26 00:02:12,800 --> 00:02:15,540 We want to get each single area. 27 00:02:15,560 --> 00:02:19,370 So in order to access each product, we need to say product. 28 00:02:20,540 --> 00:02:27,830 Product is going to be equal to is going to be equal to session. 29 00:02:29,530 --> 00:02:30,120 Cards. 30 00:02:31,200 --> 00:02:32,940 And then keep. 31 00:02:33,940 --> 00:02:37,450 This is going to get each single product as an entry. 32 00:02:37,450 --> 00:02:44,230 So this is going to return an area where the product and now we can get each single. 33 00:02:45,550 --> 00:02:51,520 It's each single or each piece of info that this product has. 34 00:02:52,030 --> 00:03:00,250 For example, each product we can say product our product name, remember in the cart restored, we 35 00:03:00,250 --> 00:03:01,360 store them in these keys. 36 00:03:01,360 --> 00:03:04,570 So we have the product ID, product name, price, image, quantity. 37 00:03:04,570 --> 00:03:05,980 So you need to use these keys. 38 00:03:06,370 --> 00:03:09,640 You cannot use other keys other than these. 39 00:03:10,330 --> 00:03:17,680 So we need to say here product, underscore item and then the product ID is going to be equal to. 40 00:03:19,380 --> 00:03:26,250 Project ID is going to be equal to the product product and we can repeat the process and it's going 41 00:03:26,250 --> 00:03:26,970 to take some time. 42 00:03:26,970 --> 00:03:29,850 So let me let me work on this quickly. 43 00:03:29,850 --> 00:03:30,960 I'm going to say product name. 44 00:03:33,900 --> 00:03:40,140 And again the name is the key for the for the name is name price image quantity. 45 00:03:40,140 --> 00:03:41,940 So here name. 46 00:03:43,180 --> 00:03:43,750 And then. 47 00:03:46,190 --> 00:03:46,790 Project. 48 00:03:48,320 --> 00:03:48,950 Image. 49 00:03:52,840 --> 00:03:53,440 Image. 50 00:03:55,300 --> 00:03:55,930 And then. 51 00:03:57,510 --> 00:03:58,110 Product. 52 00:04:03,240 --> 00:04:03,780 Price. 53 00:04:09,310 --> 00:04:10,000 And then. 54 00:04:11,830 --> 00:04:12,400 Right act. 55 00:04:14,540 --> 00:04:15,640 130. 56 00:04:18,320 --> 00:04:28,760 And here once again you need to double double check your easier because if you have a mistake here you 57 00:04:28,760 --> 00:04:34,260 will have a severe problem and you will not be able to figure out the problem easily. 58 00:04:34,280 --> 00:04:36,260 So you need to double check before moving on. 59 00:04:37,010 --> 00:04:38,360 Product ID Product Name. 60 00:04:38,360 --> 00:04:39,080 Product Price. 61 00:04:39,080 --> 00:04:40,040 Image Quantity. 62 00:04:40,700 --> 00:04:41,960 Product Name. 63 00:04:41,960 --> 00:04:42,800 Image Price. 64 00:04:42,800 --> 00:04:43,400 Quantity. 65 00:04:43,850 --> 00:04:48,380 Now we need to insert each single one into the database. 66 00:04:48,380 --> 00:04:50,270 And to do this we can use the connection. 67 00:04:50,270 --> 00:04:56,000 We can say con and then prepare and then insert. 68 00:04:57,750 --> 00:04:58,430 In Syria. 69 00:05:01,300 --> 00:05:02,570 In Insert. 70 00:05:04,310 --> 00:05:04,910 Into. 71 00:05:05,600 --> 00:05:09,770 Into what we need to insert into now into the order items. 72 00:05:10,400 --> 00:05:14,510 So I'm going to say order underscore items, order items. 73 00:05:14,510 --> 00:05:16,040 And then what do we want to insert? 74 00:05:16,430 --> 00:05:25,150 We want to insert the, um, the order ID, the product ID, the product name, the product image, 75 00:05:25,160 --> 00:05:26,510 the user ID and the order date. 76 00:05:27,020 --> 00:05:27,620 And the. 77 00:05:27,890 --> 00:05:31,700 The item ID is going to be given by the database automatically. 78 00:05:32,720 --> 00:05:36,680 So we need to say here, we need to start with the product with the order ID. 79 00:05:37,400 --> 00:05:41,780 So I'm going to say here, order underscore ID, comma. 80 00:05:41,780 --> 00:05:44,810 And then the second is the product. 81 00:05:44,810 --> 00:05:47,270 ID product. 82 00:05:51,680 --> 00:05:51,980 I'd. 83 00:05:53,000 --> 00:05:56,060 The third is product name and then image. 84 00:05:57,300 --> 00:06:02,940 Product name and then product image. 85 00:06:04,330 --> 00:06:06,460 And lastly, we have the. 86 00:06:08,040 --> 00:06:17,030 User I.D. and the order, the user I.D. and then order date. 87 00:06:18,620 --> 00:06:23,650 So the order date we have the order date, but we don't have the we have everything actually. 88 00:06:23,660 --> 00:06:29,690 So let me add the new line first and then I'm going to say values. 89 00:06:31,250 --> 00:06:31,900 The. 90 00:06:35,570 --> 00:06:36,140 Values. 91 00:06:36,770 --> 00:06:41,510 And you need to be very cautious because if you have any problem with this, with the syntax of this 92 00:06:41,570 --> 00:06:43,460 school, it's not going to work. 93 00:06:44,300 --> 00:06:46,070 So how many question marks? 94 00:06:46,070 --> 00:06:52,670 Again, you need to use question marks because otherwise you will your data will be could be under attack 95 00:06:52,670 --> 00:06:53,300 by hackers. 96 00:06:53,600 --> 00:06:59,720 And again, if you are interested in Beachbody security and security best practices, you can take my 97 00:06:59,720 --> 00:07:04,080 course about security best practices of BHP. 98 00:07:05,480 --> 00:07:11,780 So here we need one, two, three, four, five, six. 99 00:07:11,780 --> 00:07:12,890 We need to see six. 100 00:07:14,130 --> 00:07:14,880 Question marks. 101 00:07:14,880 --> 00:07:19,080 One, two, three, four, five, six. 102 00:07:19,830 --> 00:07:24,600 And then we need to store this in a variable called the empty. 103 00:07:26,760 --> 00:07:28,650 One, let's say, is the empty. 104 00:07:28,650 --> 00:07:29,820 Just the empty. 105 00:07:30,960 --> 00:07:34,770 Let's see, is the the one used to differentiate between this and the other one. 106 00:07:35,940 --> 00:07:37,620 And then I'm going to say you. 107 00:07:39,710 --> 00:07:40,100 The. 108 00:07:41,830 --> 00:07:46,460 Is the empty one bind around. 109 00:07:47,140 --> 00:07:50,200 And what are the parameters that we want to bind? 110 00:07:50,890 --> 00:07:52,780 First, we need to bind the order ID. 111 00:07:52,840 --> 00:07:55,210 So the order I.D. is is the integer. 112 00:07:55,990 --> 00:07:58,450 The product ID is integer. 113 00:07:59,200 --> 00:08:01,720 The product name is string. 114 00:08:02,230 --> 00:08:03,670 The product image is string. 115 00:08:04,180 --> 00:08:08,560 The user ID is integer. 116 00:08:09,280 --> 00:08:11,740 The order date is. 117 00:08:13,530 --> 00:08:16,560 A string and then comma and then. 118 00:08:16,950 --> 00:08:18,450 Let's start with the order I.D.. 119 00:08:18,780 --> 00:08:19,950 So the order I.D. is here. 120 00:08:19,980 --> 00:08:20,910 This is the order I. 121 00:08:22,350 --> 00:08:23,130 I'm going to stay here. 122 00:08:24,720 --> 00:08:25,250 Order. 123 00:08:26,380 --> 00:08:26,700 I'd. 124 00:08:28,210 --> 00:08:30,430 And then Project 80. 125 00:08:33,490 --> 00:08:34,060 Project. 126 00:08:35,310 --> 00:08:35,750 I did. 127 00:08:36,480 --> 00:08:37,110 And then. 128 00:08:38,240 --> 00:08:40,280 After the product I.D. We need the product name. 129 00:08:40,280 --> 00:08:46,340 So we have the product name, product name and then the product image. 130 00:08:48,500 --> 00:08:51,530 Product image and then the. 131 00:08:53,240 --> 00:08:55,640 We also need the products price and quantity. 132 00:08:55,640 --> 00:09:03,440 So I forgot to add here the product name and the price and the quantity. 133 00:09:04,520 --> 00:09:06,890 So we need to adhere to the Laney idea. 134 00:09:06,920 --> 00:09:07,670 Let me say. 135 00:09:09,270 --> 00:09:10,830 Let me hear say. 136 00:09:12,750 --> 00:09:13,290 Structure. 137 00:09:13,290 --> 00:09:16,500 And let me add the product here. 138 00:09:16,500 --> 00:09:17,130 I'm going to add. 139 00:09:18,410 --> 00:09:20,000 The quantity. 140 00:09:20,000 --> 00:09:21,290 The quantity is very important. 141 00:09:21,290 --> 00:09:25,250 So I'm going to here I'm going to add two columns. 142 00:09:27,310 --> 00:09:28,240 After the image. 143 00:09:31,660 --> 00:09:35,950 And these columns are going to be the product price and the product quantity. 144 00:09:42,040 --> 00:09:47,380 So the product price is going to be integer is going to be decimal, actually. 145 00:09:48,100 --> 00:09:49,810 And is going to be. 146 00:09:52,290 --> 00:09:58,530 He's going to be for six, let's say six to. 147 00:09:59,550 --> 00:10:01,620 And the quantity is integer. 148 00:10:02,490 --> 00:10:03,870 And that's it. 149 00:10:03,870 --> 00:10:06,380 It's actually the missing. 150 00:10:06,380 --> 00:10:06,930 Mm. 151 00:10:07,030 --> 00:10:14,850 That this email so we have this email and seeks means that it's going to be six digits. 152 00:10:15,150 --> 00:10:17,730 And two of these digits are going to be. 153 00:10:20,970 --> 00:10:27,540 Two of these six are going to be the points are going to be digits after the point. 154 00:10:28,620 --> 00:10:30,780 So let me click on Save and. 155 00:10:32,730 --> 00:10:40,560 Now, if I click on product items, you will find that we have your product price and product quantity. 156 00:10:41,010 --> 00:10:41,750 So this is correct. 157 00:10:41,760 --> 00:10:50,820 Let me now go back and here let me insert after the product image, we need to say product, product, 158 00:10:51,720 --> 00:10:59,490 underscore price and then comma, product underscore one duty and then comma. 159 00:11:00,150 --> 00:11:10,770 And he is going to say, I assess ISIS and then the the price and the quantity are integers. 160 00:11:10,770 --> 00:11:17,760 So we need to say, I, I, and then I guess and then here we need to increase the number of question 161 00:11:17,760 --> 00:11:18,150 marks. 162 00:11:18,660 --> 00:11:24,270 So I'm going to increase the question marks to eight because now we have eight parameters. 163 00:11:24,570 --> 00:11:28,620 One, two, three, four, five, six, seven, eight. 164 00:11:30,170 --> 00:11:33,650 And here I'm going to say product, image and then product. 165 00:11:34,580 --> 00:11:35,150 Price. 166 00:11:35,750 --> 00:11:39,110 And then product quantity. 167 00:11:39,710 --> 00:11:40,370 And then. 168 00:11:42,650 --> 00:11:43,130 Product. 169 00:11:43,450 --> 00:11:44,120 The user. 170 00:11:45,440 --> 00:11:46,040 User ID. 171 00:11:47,210 --> 00:11:50,540 So the last the last parameter is the order date. 172 00:11:51,260 --> 00:11:54,320 Order date and you can get the order date from. 173 00:11:55,190 --> 00:12:00,800 Previously we have it and we have either the order date and the user I.D. so there is no need to create 174 00:12:00,800 --> 00:12:01,580 it one more time. 175 00:12:02,450 --> 00:12:07,910 Finally, we need to excuse the statement I'm going to say is the empty and then execute. 176 00:12:08,720 --> 00:12:11,360 This is going to execute the statement and that's it. 177 00:12:11,810 --> 00:12:13,430 This is for for this part. 178 00:12:13,430 --> 00:12:16,480 So for this part, we just need to do this. 179 00:12:16,490 --> 00:12:20,190 So let's now test, maybe save everything else. 180 00:12:20,420 --> 00:12:22,430 Heading over to the browser and test. 181 00:12:23,030 --> 00:12:26,300 So not only the browser, let me add these into the cart. 182 00:12:26,300 --> 00:12:32,720 So let me first start from from the beginning, I'm going to go to the homepage and I'm going to click 183 00:12:32,720 --> 00:12:33,140 on. 184 00:12:35,150 --> 00:12:39,050 I'm going to add this to CART and I'm going to add another product to CART. 185 00:12:39,680 --> 00:12:42,600 So we already have these products added to cart limit. 186 00:12:42,620 --> 00:12:44,240 Click on checkout. 187 00:12:45,290 --> 00:12:46,470 Let me fill out this form. 188 00:12:47,000 --> 00:12:49,880 So after I filled out this form limit, click on place order. 189 00:12:50,660 --> 00:12:53,030 And we have a problem here in line 47. 190 00:12:53,540 --> 00:12:55,910 So the line 47, I have a problem. 191 00:12:55,910 --> 00:12:59,840 It says 47, I should say, is the empty one. 192 00:13:00,410 --> 00:13:03,050 So this is a simple mistake. 193 00:13:03,500 --> 00:13:10,070 And they also have a problem with the here, I should say, order items with an and so as he told us, 194 00:13:10,280 --> 00:13:13,590 a very simple mistake could cause so many problems. 195 00:13:13,590 --> 00:13:20,570 So here order underscore items because the table is order underscore items with that is let's try one 196 00:13:20,570 --> 00:13:21,080 more time. 197 00:13:21,620 --> 00:13:25,460 So I'm going to go back to the home page and I'm going to add this to CART. 198 00:13:25,460 --> 00:13:27,890 We already have this in the cards and let me click on checkout. 199 00:13:28,520 --> 00:13:30,110 Now let me fill out this form quickly. 200 00:13:30,470 --> 00:13:33,440 So after I have filled out this form, let me click on place order. 201 00:13:33,440 --> 00:13:36,110 And as you can see, nothing will happen. 202 00:13:36,140 --> 00:13:40,840 And because I didn't display anything but let's check the database now. 203 00:13:40,840 --> 00:13:43,550 Only the orders in the order items we should have. 204 00:13:44,150 --> 00:13:45,340 We should have two items. 205 00:13:45,350 --> 00:13:46,550 As you can see, we have two items. 206 00:13:46,970 --> 00:13:52,620 The first item is the is the white juice and the second item is green back and thus. 207 00:13:52,790 --> 00:13:53,330 That's correct. 208 00:13:53,750 --> 00:13:59,420 And the name of the images, the prices, the quantities, everything is has been stored here. 209 00:13:59,720 --> 00:14:01,310 And notice something important. 210 00:14:01,730 --> 00:14:03,020 The order ID is the same. 211 00:14:03,410 --> 00:14:09,620 There already is four and four because the same person, which is me, has ordered these two in all 212 00:14:09,620 --> 00:14:11,030 in one single order. 213 00:14:11,690 --> 00:14:13,760 So the order is going to be one. 214 00:14:13,880 --> 00:14:15,860 So the order is not order number four. 215 00:14:16,400 --> 00:14:21,170 And this order, the details of this order, the details is this. 216 00:14:22,640 --> 00:14:24,120 Are these two lines? 217 00:14:24,140 --> 00:14:25,220 Are these through her eyes? 218 00:14:25,550 --> 00:14:29,930 The details of the order are the white rose and the green back. 219 00:14:29,960 --> 00:14:35,270 This is a very important concept, and by using the order I.D., we will be able to do awesome things.