7. Food Order Website with PHP and MySQL (Adding and Displaying Foods)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone i am busy tapa and welcome back to my channel today i'm back with new episode of our food order website with php and mysql and today we'll start food module so without further ado let's start our tutorial [Music] so first of all let's log into our admin panel and our url to go to our login page is local slash food order slash admin and if you just type up to here like food order is our main uh project folder and admin for our addon panel and press enter and it will redirect you to login page and here just enter your username and password my username and password is admin and admin hope you remember your username and password and then click on login login successful and we have already completed our category module we have successfully added functionality like add category update and delete and today we will do the same with our food module so today we'll work on adding food and displaying the food so let's go back to our code editor which is visual studio code and here i'll open manage food.psp and here first we will work on adding the food in database so let's create add food dot php page so along with add admin and add category let's create a new file so i'll click on new file and i'll give its name as address for dot php so this is uh add dashford.psp and let's link uh this page to our manage foot dot psp page so in manage that for psp go to add food so here is our add food button and instead of this default has a pound sign here we will link our at dashfood.php file so i will open php close php and echo our site url eco url site url and then we need to go inside admin and inside admin we have add dash food dot psp so that's the link let's save it by pressing ctrl and s and we will check whether our file is linked correctly or not so i'll go to add dashboard.php and here i will open php close php and i will echo i'll just echo like add food page and semicolon and save it by pressing ctrl and s and let's go back to our browser and let's refresh our manage food page so this is managed food and we have added link to our ad food dot ad food button so i'll click add food and here you can see the message ad food page so that means we have successfully linked our ad food dot php page in our manage food page if you have any error like object not found either then your link is not correct so you might you so you need to go to manage dashboard.psp and link add food.php file correctly so this is add dashford.psp and you should link this file correctly okay so now let's work on designing a form for our ad for php so instead of just displaying ad for message first thing i need to add is include uh menu and then include footer okay so i'll include ins include and we need to include menu but menu is inside our cls folder and then menu dot php semicolon let's save it by pressing ctrl ns let's go back to browser and click on add food and here we have our menu now let's add footer so i'll copy it ctrl nc and go down here i will change from menu to footer.php and save it by pressing ctrl ns let's go back and refresh the browser now we have nice footer as well now let's add our main content section so between menu and footer i'll add div with main content class c o n e and t and we have our div and inside this main content div i'll also add wrapper division with wrapper class so deep wrapper and inside this deep wrapper we will add title for title we are using h1 tag and inside h1 we will call add food that's it let's save it by pressing ctrl and s and let's go back to browser and let's refresh the browser and here we have our nice title which is add food now below this add food title we will create form to add our food okay so to design form we will look at our database structure so here is our database food dash order and this is our table food table so i'll click on tvl food and then you can just go to structure and based on this table structure we will design our form okay so let's go back to our code view so this is our code view and after s1 i'll add several break tag br and then again br and after this uh here i will create a form to add food okay so i'll open form and action will leave blank and method method is equals to post and let's add ink uh ink type as well because we will be uploading image as well so here we have image name so we need to add ink type property as well so e n c t y p type is equals to uh multi part slash form data okay and i will put the ending form tag below and inside the form tag let's create a table with width with class tv l30 uh to align our form perfectly so i'll create a table and i will give the class as well for table so our class will be class is equals to tbl dash 30 uh hope you remember uh the meaning of this class tbl 30 if you remember please add the meaning of this table in the comment below okay so that i can check whether you remember or not and inside this table we will have table row or tr and also td so first i will add tr and then td so first thing we will have it will have is a title we don't need to pass value for id because it is auto increment so the value for auto increment is inserted automatically so first thing we need title and the description so title and then we need to add on the td and here we will add input type text so input and type will be text and name will be sorry name name will be title and then we need placeholder as well so let's show y'all your placeholder is equals to here we'll pass title of the food so it will be displayed in our input type so let's save by pressing ctrl and s and let's go back to browser and let's refresh our add food page so i'll refresh add food and here you can see title and here is our placeholder input type text with placeholder so if i type anything it will disappear if it's blank then message will be displayed similarly let's add a description and since description will be longer we will be using text area so let's go back and after this tr i'll add another tr our table row and add a td and this is this script uh sun and then we'll add another td and then this will be instead of input type text this will be text area because description will be longer than uh like title so we need name we don't need id and we can go with goals and rules so that's it so it's name will be description i uh p t i o o and description uh let's save it by pressing ctrl and s let's go back and let's refresh our page so here is our description so if you increase or if you increase the rows then its height will be increased uh let's say let's call it five and let's save it by press ctrl n s and it decreases the height so five is okay and you can do same with goals as well so but uh i think that's okay for now and let's add placeholder placeholder as equals to description of the food that's it let's save it go back to our browser and let's refresh it now you can see the message which is description of the food and after description let's check the database table so after description we have price and then image name so this is for uploading the image and let's add input type uh number for price so i'll go and here i'll get under tr this is for price td and then pl i see price and then after this td and input its type will be number so num and let's uh give the name name will be price and then press solder we don't need to keep placeholder we because this is a number type so i will save it by pressing ctrl n s let's go back to browser and let's refresh and here we have our price and it's not displaying like up and down arrow i think we need to give full name number let's save it go back let's refresh and now we have up and down arrow and this won't allow any text this won't allow any text and we can only add number like 10.56 with this decimal and this input type allows only number with decimal like you can add decimal value as well as integer value but it won't allow a string value like we cannot type in later here so that's uh the input type for adding uh numerical values okay so this is input type number okay so the input type number only allows numerical value it won't allow a string value like any letters okay so hope you understand now after this we need to add a button to upload image so i'll create another tr inside this tr will add tt and this will be image select image so we can call it like yes yeah this is to select image and after this we will add td and this will be input type file so input and type will be file and then we need to give name so name is equals to give it image that's it let's save it go back to browser let's refresh the browser now we have our uh button to select the image after image we have its category featured and active so first i will add feature and active and then i will add category okay so here tr and then let's say this is td and this will be category jio our category and here we need to display all the category from database so for now we need to create a drop down to create a drop down we use select tag so select type will create drop down and we don't need to give id but we need to keep the name so name will be category and inside the select we need to give option so uh this option will be uh the drop down values so let's create option opti option and here we will display the name like category for example food and here we need to pass the value and if we see the database structure we are saving category id not the category name so here we need to uh insert category id for example one and if i copy and paste paste it here so it might be like yes and a c s is next let's say a bit go back to our browser let's say the value as well value is two let's save it go back to our browser and let's refresh our add food page and here you can see the drop down food and snacks for now i have just added two dummy uh values for our category drop down menu but later we will get all the category from our this category section so all of this added category we will display all of this category in our add food section here okay so for now let's go with dummy data i will add a featured and active so i'll add featured and active and then we'll work on displaying category from database in our drop down menu okay so let's go back to our code after category we have is featured so tr and then td this is yeah t you already featured and then td and here we for feature we will be using using radio input type so input type will be radio and here we need to give value if you remember from our previous episode so value will be first will be like yes and here we need to display the value as well and another will be input this will be also radio and i forgot to give the name you are going to give name as well name is equals to feature to you already featured and radio you need to get name is equals to featured and here we need to give value is equals to no so first one is yes second one will be no that's it so this will be displayed uh in our web and these are the values that will be saved in database okay i refresh that page so here we have uh featured radio button and only one of this will be selected because the name for both of this input type is featured so only one will be selected at a time and after feature we need is active so tr and then td this will be active and here let's add another column and this will also be input type radius so i'll just copy this both of these and paste it here and let's push it inside so they will align perfectly and instead of feature this is active so i'll change it to active and this will also be active that's it let's save it value will remain same yes and no only the name is changed so let's say go back to our browser i refresh it so here we have feature and active only one of either yes or no is selected we cannot select both of them that's it now let's add a button to submit the page or submit the form at last so i'll go back after active here uh i will add a button to submit so td let's add cold span as well goal span is equals to 2 because we are creating uh two columns like first column and second column first column to uh display the title and second column for input field that's why we are using col span two and here we need to add input type submit to submit the form so in food and type will be submit name will be submit input type submit name will be submit and then value will be add food and we need to give a color or class for our button as well so class will be btn secondary so let's say by pressing ctrl ns and let's go back to our browser and i'll refresh it now we have our button add food as well so we have successfully designed the form now one last thing uh we have to add is display the category from database okay so let's work on displaying the category from database so i'll go back to our code editor and let's go to our category section so here instead of adding uh manual options we need to display them from our database okay so after this select and before option uh i will make some space to add php code so that we can get these categories from database so i will open php close php and here we will create php code like create php go to display sorry to display display display categories from database and first thing we need to do is create sql query sorry comment so this will be create sql to get all uh we will only display active categories so active categories uh from database and then we will display on uh drop down so we'll do these two things so let's create sql query and execute it so to create sql query i'll create a variable and i'll call a variable as dollar sql and let's create a sql query okay so it will be select asterisk all from tbl underscore category and we will use where keyword where active is equals to yes okay so this is yes and we are wrapping areas inside single quote uh because this is a string value and string value needs to be wrapped inside code okay so if it was uh like if it was an integer value we did not need this single quote but since this is a string value we need to wrap it inside single quote okay so let's go back to our browser and let's see the category and here we have uh active option so based on this active option we will display uh this category while adding food okay so if this value like if active is no then this won't be displayed on add 4d section but if the value for active is yes then this will be displayed on add food section okay so let's go back to our adword so here we'll display those categories from database based on that active value so let's go back to our code so this is our sql query now we need to execute it so i will create a dollar raised variable here we will sorry we don't do good here we will execute the query so mysqli underscore masculine query dollar connection and then dollar sql so let's add comment for this as well so this is executing query then let's count the rules to check whether we have categories or not so i'll call it count rules uh to check let's see to check whether we have categories uh not so here i will create a variable called dollar count is equals to my sqli underscore num underscore roots and here we will pass dollar raise so this holds the value from query executed so we need to pass that value and need to count the rows so if we have uh the rows or if the count is greater than 0 then we have rows if the count is equal to 0 or less than 0 then we do not have any values okay so let's check so if count is greater then zero we have categories else we do not not have categories okay so if dollar count is greater than zero that means we have categories i have categories and else else else i'll put this color this is down here else we do not have category and we will uh display the values based on this so when we do not have categories i will just display none no category uh found so let's give that option for that i need to break the php and then again open the php and here between this php i'll add this html tag which is option so i'll copy it and i can paste it here and here i'll call it as no categories found and i will give its value as zero so that's it and here what we need to do is since we have categories and in database there could be many categories in our database so we need to use while loop to display all the categories okay so let's use while loop to get all the categories so i'll add row i'll create a ruby level inside while loop and use my sqli underscore fetch underscore as hook and here we need to pass dollar risk and inside this while loop we will get uh the title of the category as well as id of the category and we will display this option inside this while loop so that we can get all the categories from database okay so here let's get get the value let's get the details of category categories so first i'll get his id and id will be dollar row and then id id and then another thing is dollar tit the title is equals dollar row and then title so we only need these two things because in option section in option tag we are displaying the title and adding the id value so i will use this to i'll this i'll use this tag to display our categories in our drop down section so ctrl and s if we go back and browser we still are not getting the categories from our database but now let's add those title from database okay so i will end the php here and then open php again and between this php i will display uh categories from database using option tag okay so i will paste it here and here in food here i will delete foot and instead i will just echo or display the category title echo dollar title and here i will display the id php let's say echo dollar id okay so that's it now i'll create a space up and below this meta tag uh this html tag so i will remove this manual option values i will save it by pressing ctrl and s so what we have done is we have created the sql query to get all the active categories from our database and then execute the query and then count the number of rows to check whether we have categories on database or not and if we have categories in database then we used while loop to get all the categories from database and then we displayed using option tag and else when we do not have any categories to display then we are displaying no category found with below zero okay so let's save it and go back to our browser and i'll refresh it now here you can see the categories we have added currently we are getting two categories test and category with image so i'll go to category and here we have three categories but we are only getting two test and category with image because the new category the value of active for new category is no so that's why we are not getting uh this category in our ad food section okay so quickly i will change the name of these categories into food drinks and snacks so i'll update category so let's call it food food update and then let's call it snacks snacks update update i'll change this to let's see drinks and update so now we have food snacks and drinks so i'll go to food add food so if i drop down click and drop down we can see food and snacks now let's go to category and update the active status for this as well so i'll click on update category and i'll click on yes for active so click on update category now let's go to food and if we click on add food and click and drop down now we can see food snacks and drinks so this is how we can like display or hide uh some some data from our database okay so this is how we use sql queries to filter all the things from database so if you want to learn more about databases or sql queries then i have a course for beginners i'll put the link in the description you can click on that link and if you are interested really interested about more of the databases then uh feel free to check that course as well okay it's free so we have successfully uh designed a form for our ad food section now we will add or we will insert this data in our database okay so let's go back to our code and here i have one question for you guys okay so do you know why we are saving id uh instead of title in our value do you know if you know or if you don't know please let me let me know or answer in the comment below and i will tell the reason behind inserting id instead of listing value or title in this value for our drop down okay i will tell i will talk about this thing in our next episode okay so if you whether you know or you don't know please comment below okay so let's go back and add the functionality to insert all this data in database so first we need to check whether this ad food button is selected or not and we only want to add the data and database whenever this button is clicked okay so let's go at the end of the form and after the form ends here i will create a php code to insert data into database so here i'll open php close php and between this php we will what we'll do is we will check whether check whether the button is clicked or not so if sorry if it said dollar underscore sorry not sassen dollar underscore post and then submit then only we will add the food in database otherwise we won't do anything okay so i'll save it go back to our browser refresh the browser i'll click on add food and i have not added an echo so to check let's add eco and here we can display the message like see okay it clicked save it by pressing ctrl and s go back to our browser let's rephrase the form and click on add food now you can see the value clicked so we only want to process the form and insert the data in database whenever this button is clicked so let's go back to code and here i will comment out this echo instead what we will do is our step one is to our step one is to get the data so get the data from form and then two is to insert into database and before inserting what we need to do is we also need to upload the image if selected so here into step 2 we need to upload the image if selected and after inserting into database what we will do is we will redirect uh redirect with message to manage food page that's it now let's get the data so first let's get the data let's go back to our browser and we have title description price so let's get those value so let's create a variable title is equals to dollar underscore post and then title after title we have dollar description dser i p t tion description is equals to dollar underscore post and then description d-s-c-r-i-p-t-i-o-n description after description we have price so dollar price is equals to dollar underscore post and then price price and after price we need to select the image so selecting the image we will do in step two uh so i will skip this select image part so instead i will get the category and feature an active so let's get category dollar category is equals to dollar underscore sorry dollar underscore post and then get gory after that we have it featured and active so for feature and active now we need to check whether radio button for feature active are checked or not if checked we will get the value accordingly else we will set the default value as no so if is set if we set a dollar underscore post and then [Music] feature then our dollar featured is equals to dollar underscore post feature else our dollar feature value will share the default value for featured is equals to so i will call default value as no let's call it setting default value that's it now let's get the value for active as well so if it's it dollar underscore post and then this will be active active if set then we will get the value accordingly so dollar active sct iv dollar active is equals to dollar underscore post active and then else uh if the button is not selected then we will set the default value so dollar active will be no this is our default value default value that's it so we have obtained all the value except uh the image part so before uploading the image what we need to check is whether uh the select image button is clicked or not so let's check check whether the select image is clicked or not and upload the image only if the image is selected selected so first let's uh let's check whether the image is whether the button is clicked or not so if uh iss it is set and then sorry not this one if we said uh dollar underscore files and then we need to give the name uh we need to add the name that we have keyboard while adding the buttons so the name we have given is image so we need to add the same name while getting the value for our uh image select button so dollar underscore files image and here we need to get the name of the image as well so here i'll add name so i have already shown uh the values carried by dollar underscore files while adding the functionality in category so hope you remember if you don't please say watch the video on adding the functionality to add category once again you will be you will remember everything or just google about dollar on discord files in php and you will get all the details okay but if you are confused or if you have any queries then you can always comment below and i will get back to you okay so this is how we check whether the button is selected or not if the button is selected then we will get the details details of the selected else we will set default value for our image name property okay so i'll create a variable called image name underscore name and we'll set its default value as null or blank okay so setting default value as blank bla nk okay because we have a blank image name is blank because image is not selected that means our select button is not clicked okay so if the select button is clicked then we will get all the details of the selected image but if the image if the select button is not clicked then we will give the default image name as blank that's it now let's uh get the detail of the selected image that means image name so dollar image underscore name is equals to dollar underscore files and we need to get image and its name name that's it and let's check whether the image is selected or not check whether the image is selected or not and upload upload image only if selected okay so this if condition checks whether the button is clicked or not and this verifies whether image is selected or not okay so let's save it go back to our browser and let's refresh the browser so what i mean is the first if condition will check whether this button is clicked or not clicking this button does not verify that our image is selected sometimes i may click cancel and no file is chosen but i have clicked the button right so and the second if condition will check whether we have selected image or not so when we have selected the image then uh this dollar underscore files or this button will have our name of the image so this verifies whether we have selected image or not when we have not selected the image then uh this value will be empty so let's check that so we have already obtained the image name so we will check so if the image is selected then this won't be blank but if image is not selected then this remains blank so let's check so if dollar image name is not is equals to blank which means image is selected it means image sorry image is selected okay so if image name is not black if its value is not empty that means image is selected if its value is empty that means image is not selected and we need to uh upload the image only when image name is selected right so this means image is selected and when image is image name is selected we need to a rename the image and second thing we need to do is b upload the image okay so to rename the image what we do is we need to get our extension like dot jpg dot png dot gif of the selected image okay so here i'll add the comment get the extension extra e and of selected image which is like jpg p n g g i f a t c it is c and to get the extension what we do is dollar extension is equal to we use explode array and here we need to add how we want to explode the value or the string value and here we need to pass dollar image name so i have already discussed about the explode array in while adding the functionality in add category so if you want to know more please google once and i will try to uh explain again if if you have if you if you get any more confusion then add the comment as well but first i will add the code and i will explain it to you okay so this is it so what this explored function does is for example our image might be like vz uh that's tapa dot jpg so let's assume that our image name is visit us tapa.jpg okay so what this what this explode will do is and here we have passed a a signal or symbol that we want to break the whole name into things okay so what this explode function will do is it will look at the variable or look at the sentence we have provided in this case we have provided image name so this value which is selected from a button from our add foot page so this image name will have value like image dash vijaythapa dot jpg and what this explorer function will do is this will break the whole name into like wizard as tapa and jpg and what why this is doing or the way this is breaking into two things because we have a pass dot as a symbol and we want to break this whole thing into two by based on this fully stop sign okay but we do not want the first thing or anything before that we only want and we are only getting the extension and extensions usually are at the end of our image name so we are adding end function here so what will what it will do is it will only select last part of dot okay so that's how we get extension after that we get uh we create create new name for image okay so here we can create a new name for that i will call it as image name so this is a old image name and this will be new image name okay so here i will give a custom name like food dash name and this and here i will add like random function random zero zero zero zero and then nine nine nine nine so this is minimum value and this is maximum value after that i will concatenate again and here i will pass fully stop and then we need to add dollar extension okay sorry dollar extension that's it so uh this line of code will create new image name like new image image name maybe like food name because we have given that name as food underscore name and this function will this is the minimum value and this is the maximum value and this random function will generate random integer based on this minimum and maximum value okay so this image name might be food that's named as like 6 6 57 and after that we have also concatenated fully stop sign here so we have our default name and then random value then fully stuff so there will have dot and this extension or this dollar extension will get the default extension which might be like jpg or gif so our new name might be like food dash named at 657.jpg okay so initially our image name could be like this one bj dhaba jpg but we are renaming this name into food dash named at 657.jpg okay so this is it after that after renaming what we need to do is we need to upload the image and to upload the image we need to get get the source file source path and destination path path so source path is the path where image is currently located so let's create a source path i will comment here source path is is the current is the current location of of the image which is like dollar yes rc is equals to uh dollar underscore files and then image and then tmp underscore path okay i think this is not tmp on this one this is tmp underscore name so this is it so this will get uh the source path of our image and then we need to get uh destinations path [Music] for the image to be uploaded so here i will create a destination path is equals to here we need to uh give the destination path as we have created folder for our category let's create a folder for our food inside our images folder okay so this is our images folder inside images along with category i will create a new folder and i'll call it as food okay so we have images for images folder and then we have category and food okay so to upload the image in this folder we need to get out of this admin folder because our ad food page is inside admin so we need to get out of our admin folder and then we need to get inside images folder and then we need to get inside food folder and then we need to give the image name okay so here i will concatenate dollar image underscore name okay so we are uploading this image inside our images folder inside our food folder okay so that's it now finally upload image food image for that i will create a variable called dollar upload upload upload is equals to and our function is move underscore uploaded underscore file so uh this is the function to upload the file in our folder and here we need to give our source path and then destination path okay so here semicolon so this function move underscore uploaded on the underscore file will upload our uh file from source uh path to destination path okay so that's it and then we need to check whether image uploaded or not so to check we'll use if dollar upload and it's equals is equals to false if the upload value is false that means fail to upload the image and when failed to upload the image we need to redirect to add food page with error message and we also need to stop the process okay so twist up the process what we do is we use add keyword or add a function we use dive function uh what uh what are what we are doing it if we fail to uh upload the image then we do not want uh this all of this data to be saved into database so that's why we need to use dive function to stop the process and uh here we need to redirect to our ad food page with error message okay so first i will set session and i will call it as upload and here i will add or i will create a division within our class so div div div and let's give a class is equals to error and here we'll add a message which is fail to upload image that's it and then we need to redirect to retire we use header so header and then location location and then concatenate site you are l and after site url we go to admin folder and then add dash food dot php so we are passing this message to our current page which is add dashboard.psp okay so let's go to the top and we will display or we will check whether uh the session is set or not and if the session is set then we will display the message so here after beer i'll open the php close the php and here let's check if it's set dollar underscore session sorry dollar underscore session then upload upload upload if set then we will display the message echo sorry dollar underscore session and then upload and onset dollar underscore season upload that's it and if we fail to upload then this message will be displayed else we don't need to display anything so here what we have done is we have successfully uploaded it we have successfully added the code to upload the image and also display the message if we fail to upload now after this part we need to insert the data into database okay so to insert the data into test database we need to create a sql query so create a sql query to save or add food i'll create dollar sql too because we have already created sql while uh getting the categories from database we have already used our we have already created uh sql variable here so i don't want to conflict with this one so that's why i have created sql 2 so here is sql 2 so here let's create a query so insert into tbl underscore foot and set will state the value for every column so here we have columns like title description price image name category feature active and we don't need to pass the value for id because it is auto increment okay so i'll start with title is equals to uh dollar title and then description is equals to dollar dollar description and then we need to pass title description and then price so price is equals to dollar price and then so let's check what we have uh title description price and category and we also have image name when image is selected we have image name and we have new image name when image is not selected we have blank so after price what we have after price we have image name so we can pass the value for image name is equals to dollar image name that's it and then we have category underscore id so we need to add exact thing category underscore id and for price we do not need to give this single quote because price is a numerical value we only need to give a single quote for string value title listing value description is string value image name is distinction uh string image name is string value but price is numerical value as well as category id and for category id what we are using is variable category only so we draw we will add this so this is dollar category so for numerical value we do not need to give single quote but for string value we need to give single quote okay so remember that africa after category id we are featured and active so let's say yeah a tu already feature is equals to and then for feature we need to add single quote because this is a string value and then active is equals to dollars active so that's it and we don't need to add comma at the end of the column so this is the last column so at the last column we don't need to add comma okay so and for you to remember i will add a comment here for numerical value we do not need not need to pass value inside quotes but for string value it is compulsory to add quotes okay so that's it hope you will remember this one so for a string value like title description image name featured and active we have passed the value inside single quote but for numerical value like price and category id we have not added quote okay now we need to execute the query execute the query so i'll create dollar raise to is equals to mysql i underscore query and then dollar connection and then dollar sql that's it and check whether data inserted uh not if data is inserted then we will redirect uh to our manage food page with success message uh but if failed then we will redirect with error message okay so if dollar raise to raise to is equal to is equals to true that means data inserted successfully else fail to insert data okay so here i will create a session message system and then add and here i will create a division with success message so div slash div and let's add the class c lss class is equals to success and here we'll pass the message which is food and date successfully and then we need to redirect to our manage food so headers and then location and here we need to concatenate site url and then admin and then manage dash for dot php okay so that's it so i'll just copy this and add for our failure message as well so inside else statement i'll paste it here and this will be error and here we need to add fail message so fail to add food that's it so here so i will cut this step from here and i've got or i'll paste that message here because we are redirecting in this section so that's it so let's save it and let's go back to our manage food page and here we will check whether a session is set or not if the session is set then we will display the message okay so after this br i will open the psp close the php and here we will check whether system is set or not so if is set dollar underscore season and then like add then we will display the session to display we use echo echo dollar underscore session add and also onset dollar underscore session and okay so that's it i will save it by pressing ctrl and s and let's go back to our browser and let's refresh our advert page and i will fill the form with this extension form filler and here i will choose one of the file i'll go to desktop and i'll choose one of the file for now i think i will choose this one click on open and i'll click on add food food acted successfully so let's go to our database so first i'll go to database and i will click on browse for our table food so our table food database column is selected so i'll go to browse and here i think i need to refresh the database it said the database uh inserted successfully data inserted successfully but we are not getting any data in database i think it's an error so if you go to the code and if you go to the food food image is uploaded successfully but why are we not getting data in database i refresh again tbl tvl category is here we have tvl food and we should have table food but data is not inserted but why our message is sewn so add error fail to add food so the error is we have created sql 2 but here ipads ah but here i passed sql so here it needs to be sql 2 so that's the error so let's save it go back to our browser and let's refresh uh the page let's click on add food and here i will click on add all form filler extension and now click on add food and food added successfully let's go back to our database and let's refresh the database now here we have our value okay so id1 title description price i have not selected image image this time we have category featured and active value so i'll go back to our code editor and here we have one image that we selected for at the first time so i'll delete it from here so i only want to delete this one so i would read this delete food name move to recycle bin that's it so now we do not have any images in our food folder so i'll go back to our project and add food click on add food add the details i will select the file i'll select this file and click on add food food added successfully let's go to our database refresh the database and we have our second value and title id title description price and we have our image name as we have renamed food dash name random value and our extension category feature and active okay so we have successfully added data or food in database and i hope we have uploaded image as well so our image is uploaded so this is it guys we have successfully added the functionality to add the food in a database as well as upload the image in our food folder now we will work on displaying the food that are inserted in database into our managed food section okay so here we have our managed food and instead of these things we will display the detail of our food okay so let's go back and here let's update our column name so what we have is uh sn full name we will replace this full name and username so instead of full name and username let's display the title and price and image okay so title uh price image feature and active okay so let's display title uh price image feature and active so i'll go back to our code view and instead of full name i will display like title title title and then price and then image and then let's add that not tdth and this will be featured and then that's active that's it so total we have one two three four five six and last one will be ts accents accents so like title will be like uh title can be like burger king and then uh price let's say uh let's add dollars and then uh 20 let's add 20 and after that we will display image so image and after that we have featured and active so td featured like yes and then active active active will also be yes or no value so i'll say ss so that's it let's remove these two column trtr i'll remove this two column and i will only remain with one column so we have this is for title and this will be the value from database and we will use while loop to get all the data from database okay so for now i'll save it go back to our browser and refresh it so here we have title price image feature active and action button okay so that's it so let's display or let's get the value from database and display in our management so here i will open php close psp and inside this i will create first thing we need to do is create a sql query create sql query to get all to get all the uh to get all the food so dollar sql is equals to select asterisk or all from f r o m t b l underscore food that's it and then we need to execute the query so execute the query dollar res is equals to my sqli uh underscore query and here we need pass dollar connection and connection and then dollar sql that's it and then we need to count the rows so count rows to know whether uh to check let's say to check whether we have food or not so dollar count is equals to mysql mysql i underscore num underscore rules mysql and resume underscore rules and here we need to pass dollar raise and if the count is greater than dollar count count is greater than zero then we have we have food and database else else for not added and database when food is not added in this database then we will then we will display the message so i will use echo because this is a thing this will be a single line html that's why i'm not breaking php instead i am writing html inside php so echo we need row and then table row close and inside this row we need td and then td close and we need to call span as well c o l s p a n is equals to how many columns do we have one two three four five six seven so seven we merge seven columns and inside this column uh we will display the message like food not added yet okay so and here in column we can give the class as well class is equals to let's say error and this will display the message in red color so that's it in previous section we need to in previous uh modules we used to break the php and add the row and column like in manage category if we go here and here we broke the php and just write the single html code between the php end and php open but this time i have not broken the php but instead i have just written the html code inside php okay so this is how you can write html code inside php as well so if you have any confusion then please let me know in the comment i'd be more than happy to explain you okay so now let's get the food from database and display all the food okay so [Music] get the foods from database and display for that we will use while loop and we will create dollar row dollar row is equals to my sqli underscore fetch underscore as such so this will get all the uh data in array format and this while loop will continue as long as we have data in our database okay so and here we need to pass dollar risk value and here let's get get the value from individual columns okay so first we'll get is dollar id is equals to dollar row and then column name column name is id and then we need is title so we have title price image so based on these things we need to get the value we don't need everything like we do not need description and we do not need category but we will need title price image name featured active and uh we don't need actions so we don't need to get value for accent for actions we will create other things so what we need title price image name feature and active okay so let's get title dollar title is equals to dollar row and then title title title and then here we need dollar price is equals to dollar row and then price and then we need dollar image underscore name is equals to dollar row and then image underscore name and then we'll get dollar feature feature feature is equals to dollar draw featured featured and then will get active dollar active is equals to dollar row and then active that's it now we need to display all of this value in our row okay so here now i'll break the php and then start the php and between this php i will create a row and display all of this value okay so for now i'll just copy this or i'll cut this row from here so i'll just cut this row ctrl and x and let's paste it here between this psp we'll paste it here and uh what we need to do is we need to push it inside uh to indent properly i will i also need to push it inside so it indents properly and then we will display all of the data okay so first we need to display this title so instead of burger king we'll display title php and dollar title and then i will just copy this php part i will remove this i'll just let dollar be here and paste it here so we have dollar and then psp open and echo this will be dollar price and then instead of image i will just bring it down press enter and bring it down i'll open php and echo dollar image name for now i'll just print the image name but in a moment i will check whether this image name is empty or not and if the image name is not empty then we will display the image and if the image name is empty then we will display the message okay so here we need to echo this one is featured so eco dollar featured i think this is featured right so first one is twitter and second one is active so this is feature and this is active so psp echo dollar active so that's it and here for this serial number what we used to do is we used to create uh create number variable and set default value as one so dollar as n is equals to 1 and it needs to be outside of the loop and inside of the loop what we'll do is we just open psp and then echo dollar s and plus plus okay so that's it and guys uh i have a another question for you so why don't we use uh id instead of sn do you know the reason behind uh using sn creating sn and using sn plus plus instead of dollar id please let me know in the comment and if you don't know then also let me know in the comment i will explain you but if you remember then add the comment below okay so let's continue so let's save it by pressing ctrl and s let's go back to our browser let's refresh it now you can see uh the title price image name feature and active value now let's display the image when we have image name and display the message when we do not have image name okay so let's go back and here in image section i will remove this echo and i will bring this ending php tag below here and here we'll check check whether we have image or not so if dollar image name is equal to is equals to blank or if image name is empty that means we do not have image display error message so we will echo echo and then here we will create div with error class div and then class will be error error and message will be image not added that's it and if we have image in else condition that means when image name is not blank then we have image we need to display image okay for that i will break the php and then open the psp okay so and between this i will add image tag and i will give src for source path we don't need alt so src and here i will open php close php and echo site url and then we need to go inside images slash food folder and inside this food folder we need to give image name which is the image name from our database okay so here we have our image name so we need to give this name so here we need to echo dollar image name okay so that's it let's save it and let's go back to the browser and refresh it so here we have our image but this is very big so let's resize its size so here at the end of the angle bracket i will give width is equals to i'll give 100 pixel save it go back to browser and refresh it now our image is small and nice and when we do not have image we get our message as well so that's it now let's update the button this is not update admin this is update food and delete food so here i will call it as update food and delete food that's it save it let's go back to browser let's refresh it update for delete food so that's it guys we have successfully added the functionality to add the food as well as upload upload image for the food in our database and we have also displayed uh the food that has been added in database in this managed food section and in the next episode uh we will add functionality to update food as well as delete food so thanks so much for watching if you like this video then don't forget to like share and subscribe and if you have any confusion or if you have any error then please let me know in the comment below i will reply you as soon as possible so i'll see you on new episode till then stay safe take care see you soon bye
Info
Channel: Vijay Thapa
Views: 19,516
Rating: undefined out of 5
Keywords: vijay thapa, software development, web development, programming courses, free courses, php, mysql, php project, php for beginners, food order website, food order website with php, how to create food order website, food ordering system, web development course, web development with php and mysql, display data in dropdown with php, php and mysql tutorial for beginners, php and mysql projects, learn php, php course
Id: YsrPRRLfaG0
Channel Id: undefined
Length: 86min 28sec (5188 seconds)
Published: Fri Nov 27 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.