9. Food Order Website with PHP and MySQL (Connecting Frontend and Backend)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone i'm 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 work on connecting our front end with our back end so without further ado let's start our tutorial [Music] so first of all let's go to our code view so i'll open my code editor which is visual studio code now we can close all of these codes for our backend or admin panel so i'll close all of this adword update food manage food manage category at category and admin.css and we can also minimize our admin folder for now because we don't need to work on this or we'll need to work on config for constraint.psp and we can minimize css we can minimize images and uh the first thing uh to connect our frontier with backend uh first thing we need to do is convert all of these html pages into php so we will change the extension of all of these pages and we will also create parcels for our front end we have already created partial for our admin panel uh same like same as admin panel we will also create parcels for our uh front end okay because if you see our front end which is local slash food order if you go to the front end uh you can see the menu this is home page and if you go other pages like categories of foods then here you can see the menu same menu same footer same menu and same footer so all of the pages have seen menu and simple so i will create parcels and create menu and footer file there and we will use these parcels okay so i'll close this for now and we will stay on this page and let's go to code editor and first let's convert all of this index dot uh html this html pages into php okay so first i will right click on this and then rename and i'll just rename the extension does html to dot php and same with category dashboard rename and this is psp category dashboard.psp and food search rename this is also php foodsource.psp foods dot html rename and then force dot php and index right click and then rename and this is also index.php and order right click rename this is also php okay so that's it now here we have our index.php file so this is index.php if i go to browser and reload the url then it should show our page this is index.php but our page is showing perfectly so similarly if i go to like foods dot php then our foods space is also displaying perfectly okay so that means our conversion has not affected uh on displaying any of our pages now we will create partials for our front end so along with all of these folders and files i will create uh i will create a parcel so here along with admin config.jss images i will create a folder and i'll call it ads p-r-t-i-a-l-s dash front okay i'll add front uh to separate uh parcels of admin so i'll call it as partial prt ils partials dash front okay and here is our parcels and inside this partial i will create uh two files one is menu and another one is footer okay so i'll create a new file inside parcels dash front so first one will be menu dot php and here is our main dot psp inside partial stats front and i'll go to index.php so we will be separating menu and footer only okay so first let's separate menu so i'll go to index.psp so this is index.php and here is our menu section so menu sections ends here which is navbar so navbar is our menu so from a navbar section ends and all of the above from everything above it i will cut ctrl and x cut it and paste inside menu.php okay so i'll paste it inside menu.php and here what we will do is we will just include menu.psp okay so i will open php and then close php and then ions uh include and here we need to go inside partial dash front so p r t i a l s that's front and then menu dot php okay so that's it semicolon at the end and let's save it by pressing ctrl n s and i'll go back to our browser and i will just refresh our home page so if i refresh the home page i can see the menu clearly that means our menu is included successfully similarly let's create parcels for our footer and also include the footer so let's go back to our code and in our index.psp let's go down and let's look for our footer section so here is our footer section if we see our footer has social media icons as well so what we can do is we can cut everything below social media social section so i will cut everything below social section ctrl and x and along with menu i will create new file and it will be footer dot php okay so that's it and i'll paste everything here ctrl and v and save it by pressing ctrl and s and let's go back to index.php and here we will include our footer okay so open php and then close php and between we will include i n c l u d include uh partials tl parcels dash front and then what we need to include is footer dot php okay so that's it let's save our index.psp and let's go back to our browser and i'll refresh the browser and we do not have any error uh that means our footer is also included successfully now let's uh do the same thing in all of the remaining pages that are categories.php category foods food stalls foods and order so for now i will close footer and menu and here i will minimize parcels front as well and i'll open categories dot php and we do not need nav bar section so everything above nav bar section i will delete and here i will just include php and then include clud include and then parcels front we are including a menu from parcels front so p r t i l partial so there's front and then menu.php and close semicolon so i'll just copy it copy ctrl and c and we will do same with footer so let's go down and uh here uh from social icon we do not need social section because it's all already included inside footer so everything below social we will delete and here we will include footer so i'll just paste it here ctrl and v and instead of menu we will add footer dot php let's save it and go back to browser and which change in categories dot php so let's go back to browser and here let's test categories uh dot php and enter so we have our menu as well as footer so that means our both of the parcels are included successfully now let's go back to our code and now we will change on category dashboards so open it and same as before everything above navbar sections everything above navbar section we will remove and we will paste our menu so this is our menu i i have already copied from previous section and i just pasted it here so we have our parcels that front dot menu okay so let's go to bottom and in social section everything below social section will remove and we will paste our footers so let's change our menu to footer so yeah footer.psp so let's save it and go back to browser and let's open our category dashfoods.psp so let's go to browser this is category dashboards so see it is your category dash foods.psp press enter and we can see our menu as well as footer now let's work on another page which is food source so i will open food search and here same as before we will remove everything above navbar section and we will just include our uh menu so i'll paste it here i have copied the menu link to our menu file and i pasted it here now let's go down and everything below social we will remove and paste our footer so i'll paste it here and change menu to footer that's it let's save it by pressing ctrl and as let's go back and open our food dot food source dot psp file so let's go back this is food dash search so for this search dot psp open and we can see our menu as well as footer so that's it now let's go back and again let's open our another page which is push.php so i'll open force.psp and here same as before we will remove everything above navbar section and include our menu include our menu let's go at the bottom and everything below social icon we will remove and paste our footer so remove menu and it will be footer.p footer.php save it go back to browser and open foots.psp so this is uh foots.psp we can see the menu as well as footer and let's go back to our code view and our last page is order.psp we have already indexed.psp so same as before everything above an app by section we will remove and add our menu control v and menu.php let's go down and everything below our social section will remove and paste it here and it won't be menu it is footer now footer.php let's save it go back to browser and let's replace our order.psp file so this is order.psp and this is our order page our menu and footer is displaying successfully that means it is connected so that's it now let's add link in our we can add a link in our menu so we can go and add a link in our menu so here we can add link but we need to give our full url and our full url is inside our constraints constraint.php file so we need to include this in all of the pages and the best way to include constants in all of our pages is to add inside our menu file because menu is linked on all of the pages right so if you remember in our admin uh section we have also added constraint.psp inside menu.php file so let's go at the top of the menu dot php power sales so i'll go at the top of the menu dot php i'll close all of the pages except index.php and menu so force order so at the top of the menu.php i will include psp and here we will include include constants.psp and to go to constraint.php right now uh right now we are inside our index.php or any of these pages uh because menu.php is actually included in all of these pages like index.php order food food category etc so menu.php parcels is actually a part of inducted php and to link our constant.php we need to go inside config.psp okay so we will give the path from these pages so we won't be giving path from inside the passes that front okay so we'll be giving path from these pages because this parcel is included in this page so in menu we'll give the path from this pages okay so if we want to go to constraint.php first we need to go inside folder we don't need to get out of parcels dash front folder okay so because we are on these pages so let's go to our config con fig and then co and st cons ta ntsconstants.php okay that's it let's save it and go back to browser and let's uh refresh our home page and we are not seeing any error that means our constraints dot php file is linked correctly okay so let's go back to our menu and in our main.psp now we can give links so instead of giving index.html just index.html now we will give full url so to give full url php and then here we need to echo site urls i sat u r l and since this is a home button site url is a home url so we don't need to add extra things and let's go to categories and here we will echo site url echo site url and then we need to go inside categories dot psp okay so we have categories dot php so after echo site url we need to give categories dot php okay so if we check the our constructor php our site url is for to uh foot order and slash so to go to inside categories we need to add categories dot php right so hope you understand if you are confused then please uh add comments below i will reply you and i will try to make you understand as soon as possible okay so similarly we also need to add a link to our foods so i'll close this and echo site url php echo site url and then this will be force dot php okay so that's it let's save it and we won't be creating contact page for now for now we will be focusing on uh displaying all of the menu as well all of the foods as well as categories and we'll be focusing more on uh placing the order and managing the order uh by admin okay so let's go back and i will open our food order and after refreshing our links should be changed now if i click on categories.php our categories.php page is shown if i click on foods our foodspace is shown and if i click is click on home our homepage is shown okay so that's it we have worked on adding menu as well now let's work on displaying all of these categories so these are categories and these are foods okay so let's work on displaying these categories from database okay so first let's check the categories in our add-in panel so i'll go to our admin section so to go to edm section localhost uh slash put dash order which is site url and then slash admin okay and hope you remember your username and password so i will add my username and password which is admin admin and here we have five categories and if we go to category and here we have three this is dummy data we will work on displaying uh summary data here as well uh but first let's work on category so for now we have uh three categories here okay so i'll add couple more more as well so add category and dummy data and i'll add category so this do not have any image let's add category dummy data and select image i'll add one image for now let's select this image open and add category so here we have now one two three four five five categories so let's go back to our code view and we will display categories here okay so let's go back to our code view and we do not need menu now uh we don't need constraint.php as well so in index.php in our category section okay so this is our category section explosive and it ends here okay and if you see we have three different things and this is static uh so we need to add code three times but now we will be displaying the data from database so we don't need three of these so i will delete two of these from a tag open attack close and contact close this is one and this is two so we will only be displaying one but we will uh get all the traffic database using while loop so we will display multiple times okay so i'll refresh and we have only one category now we will get all of the category from database and display it here okay so i'll add enter tag and here i'll open php close php and between here we will get the category from database and display here okay so first thing we need to do is uh create sql query to display the split display categories from database okay so dollar sql is equals to uh select all from tbl sorry tbl underscore category okay so that's it now we need to execute the query so execute the query and here we will create dollar raise is equals to my sqli underscore query and here we'll pass dollar connection dollar connection and then we need to pass dollars sql and our dollar connection file is already inside our constraint.psp and cons and our main.psp includes constraints.psp so our connection is already in this page okay so now we need to check we need to count the rules so i'll count the rules so dollar so you want to count is equals to my sql i underscore uh norm underscore rows and here we will give dollar risk and then sorry semicolon so i will add the comment here as well so count rows to check check whether the category category is available or not okay and then what we can do is uh if a category is available then the value of count will be greater than 0 and we will display uh all of this category in our front end but if the category is not available not available then we will display error message okay so let's check so if dollar count is greater than zero that means uh categories available else category is not available see a c8 gis categories not available okay avi l a b ali available okay so when categories is not available we will just display a message so i'll use echo and then here i will create a div slash diff div and i'll give a class of error deep class is equals to uh error sorry we cannot give double quote because we have already used double quote after echo so this will be error and here i will add a category not update that's it and here in when categories are available we will use while loop to display all the categories okay so let's use while loop while and i will create dollar row to get all the data from database so dollar rule mysqli underscore fetch underscore sock and here will pass dollar raise okay so that's it and inside the while we will get the values so we need to get the values like title title title image name and id first we will get id so if we go back to our browser and see so what we can see is we can see image where we can see title and we need id uh so that we can get all the foods based on this category okay so we will get these three things so let's get dollar id is equals to dollar row and then id similarly let's get title dollar title is equals to dollar row and then title jtl title and last is image name so dollar image underscore name is equals to dollar row and then image name so image image underscores name that's it now we need to display those in our html format so for that i will close psp and open psp and between this php i'll write html okay so let's write the html so to write the html what i will do is i will just cut this anchor tag and paste it paste it inside so i'll just cut it ctrl n x got it from here and i will paste between this psp so that we can loop it and display all the categories ctrl and v so we can we need to indent it properly so push it inside i'll push a div inside the anchor tag as well and here so first thing we need to change is the url to our image or we need to give image name so here i will remove this for now and i will give first i will give psp and display our site url site s i t e u r else at url and then we need to go inside our images folder so we need to go inside our images folder and then inside our so our category images are inside our category okay so we need to go inside category c a t e g o r y category and then we need to give image name okay so i'll open php close php and here i will give echo dollar image name okay so that's it and we need to do one other thing as well so we will only display the image name if image name is available okay so first we need to check whether image name is available or not okay so when image name is empty that means image is not available then we won't display the image instead we will display message so first after this div before img we need to open php and close php and here we need to check if dollar image name is equal to is equal to blank then we need to display the message so display message so echo image not available and let's add some css as well so let's add css so i will give use div so this will be ending div and before we can add opening div and here i will create class class is equals to error sorry a-r-r-o-r error and this will display the message else that means image name is available image of i label then only we will display the image okay so here i will close the php again open the psp that's it and between this psp we will display the image okay so i'll just cut this tag from here and paste inside here okay so let's paste it inside here so that's is so what we have done is we have obtained the values like id title and image name and here we want to display the image name but we also need to check whether image name or image is available or not so here we are checking whether image is available or not and when image is not available then we are displaying the message but when image name is available then we are displaying the image with image tag okay so here i will add the comment check whether image is available or not if we do not check uh this uh then we might get either whenever we do not have image name so that's why we need to check it okay now let's display the title of the category as well so here i will remove pizza and psp and then eco dollar title okay so that's it and we also have id and we will use id while giving the link okay so while giving the link here we will use id for now i will save it as it is and go back to browser and i would refresh it and here you can see all of the categories from database like we have one two three four five five categories if you go to our admin panel we have five categories and we have we are displaying all of those categories okay but they are not in proper order though they are not in proper order due to different image size we are getting our images or we are getting our category successfully but in our home page we only want to display three categories in a row okay for that what we can do is we can go to our sql query and in our sql query here we can add limit and three so this keyword will only display uh three categories or three three row of data from database okay so let's save it go back to browser and let's refresh and here now you can see only three categories though we have five categories we are only seeing three categories okay and if we go here here we have added feature as well as active and we also need to filter our categories with this okay so we only display the categories when both feature as well as active is as okay so this is home page and in homepage we want categories that is active as well as feature so let's filter with feature active in our home page so let's go back to code view and in sql before limit here we need to add where keyword which are aware and then where active is equals to sorry yes and featured is equals to yes okay so that's it let's save it and go back to browser and now let's refresh and let's see whether these things change or not okay so let's refresh and here now instead of another image this is appearing because if we see only this has feature is yes active is yes this has also feature is as active is s this is active easiest but featured is no that means we cannot display this in menu this is also no no so this is also not shown but this has yes yes okay so if i change its status as well so if i change it to no feature is no update category and go back to home page and refresh now this is also gone so this is how your data is controlled in web which has backend like php java python or asp.net okay so this is why we need a cms or we need backend to control all the data okay so hope you understand and and now i have a question okay so i hope all of you use at least one of the social media right like uh facebook or whatsapp or twitter or linkedin or anything okay so when we add add any post or when you send any messages and let's say you you did not like the post or you did not like the chat or you did not like the message okay then what we will do you will just select the option and delete it right so when you delete it do you really think your data is getting deleted what do you think guys or is it it is managed like this your when you delete its option like active is no so what do you think it is really getting deleted from database or it is just changing the status of such thing so let me know in the comment okay so but we are using this uh option to manage our category okay so now what i will do is uh i will just change these images with our previous images okay so for that i will uh go to our root folder so i will open my root folder i have installed my xampp or we have installed our root folder in local dixie and jamp and htdocs and our food order project and inside the images we have these images so these were the default images so i want to select this one this one this one this one and this one and this one i will copy it copy all of them i will cut it from here and i will paste it in desktop so i'll paste it here paste it here so that i can easily update the images in our category okay so what i have done is i have just went in i just went inside our project folder and copy copied the static or default images from there and paste it in our desktop so that we can upload these managed or well designed images in our project okay so what i will do is uh let's go back to our our browser and let's go to our admin panel and here let's update their name as well as image okay so i'll update category and i'll call it as pizza pizza and i will change the image so i will select the new image choose image and i will go to desktop and i will select uh our pizza so this is our menu image so mn or category this is our category image so i'll select this open and i'll click on update category and i will refresh our home page now we can see our well designed image similarly i will change for snacks as well so let's go to our add-on panel so what is next it's next so i will remove this image remove the name so update category and let's call it as burger so as a burger choose image go to desktop and where is our burger so pizza and then we had our burger and open an update category pizza burger let's refresh now we have pizza and burger and let's add another one so i will go here and i'll update this one so i'll change the drinks too this will be i'll call it momo this is momo in nepali and in english it's called dumpling okay so i'll just click on choose file and where is our dumpling so this is mama select open and i will change its feature to yes update category and here i'll refresh now we can see pizza burger and momo okay so if i want any of this to hide like if i want burger to hide i will just select the update category i will turn the feature as no and i'll click on update category and if i go to our home page now our burger is gone we only have two of this okay so this is how we control our data whether to show whether to show or hide okay so update category and our display this too so that's it now let's open our category space so i'll open the category space so this is our categories and here let's display all the categories that are active okay so if they are active then we will display in our categories page and if they are active as well as featured then they will be displayed on home page okay so let's display those in our categories page so i'll go to code view and i'll open categories page as well so i'll minimize this and minimize images and let's open categories page so here is our categories page so what we will do is we need we can remove all of this except one so i will remove everything all of these and i will remove everything and i will only leave one of them so i'll remove this and we only have one of the category in our categories.php so i will save it and go back to categories.php and refresh so we only have one category so here we will display the categories from our database for that we will need to [Music] add php and we will do same as before and let's open psp and then close php and here we will do is so now let's write the code to display all the food all the categories that are active in our categories.phd page okay first i will write the comments so display all the categories that are active so i'll create sql query sql query so dollar sql is equals to uh select all from uh tbl underscore category where active is equals to we only need need active if active is yes then we will display the categories okay so this is why it is important uh for you to understand basic of databases and sql query and if you don't know the basic of sql query or database then i have a course which is free so you can check that course i'll put the link in the description so it is on ms sql server if you want you can use the same technique in ms sql server as well as mysql okay you can follow the course and you can choose either mysql or msql okay so after creating sql query we need to execute the query execute the query so i will create dollar raise is equals to mysqli underscore query and here we need to pass dollar connection and then dollar sql that's it and then we need to count the rows count rows so dollar count is equals to my sqli underscore now underscore rules and here we need to pass dollar race and then check whether category get go is available or not so if dollar count is greater than zero that means categories available categories of i label uh else else category it's not available okay when categories are not available we'll just display the message so i will use sorry echo and then i will add division div and division close and here i will add class as well class is equals to error and here i will add a message like category not found for you and you found that's it not forged not found and then uh inside when categories are available we will use while loop to display all the categories from database okay so here i will use while loop and then i'll create dollar row variable controls it dollar row is equals to my sqli underscore fetch underscore so so this will get all the data from database in our row so here we need to pass dollar risk that's it and here we will get all the get the values so we get dollar id is equals to dollar row and here we need to get id and similarly we'll get title animate name so dollar title is equals to dollar row image this is title not image name title title and here we will get dollar image uh underscore name is equals to dollar row and then image name so image underscore name that's it now we need to add this html code inside while loop so i will just break php and open php so i will open php and between this php i will write html code okay so inside here i write html code so i'll just cut this uh from starting anchor attack to ending anchor that and i will add inside the php uh ctrl and v and let's push them inside for proper indentation i will push this division inside as well and here first i will display the title and then i will work on image because we need to check whether image is available or not so instead of pizza i will display from database php echo dollar title that's it now we need to check whether image name is available or not and display the image name when image name is available when image name is notable not available then we will display error message okay so here i will open php close php and inside it we will check if dollar image name is equal to is equal to empty that means image is not available image not available else else image available when image is not available we will just display the error message so i will just copy this message from here ctrl nc and i'll paste it here ctrl and v and i will call the error or error s this is not category this is image image not found and in else we need to add this html text so i will close the psp once again and open the psp and between this psp we write html tag which is this one okay so i'll cut it from here ctrl x i will paste it here ctrl v and here we need to give the link proper link so i'll remove it php and then close php echo site url and then we need to go inside images slash category images last category this is images and inside category we need to go and here we need to get image names so i'll open psp and then eco dollar image name okay so that's it now let's save it and go back to browser and this is our categories dot php so i'll refresh it here now we can see all the images that are active okay so if you go to add in panel this is home page if you go to add panel so this one is active this one is active this one is also active and this one is also active it is not feature but it is active right so when it is active it will be displayed on categories page when it is both active as well as featured then this will be displayed on home page okay so that's it this is how we manage uh all of the things uh from our admin panel okay so that's it so we have worked on categories as well as a category section of homepage now let's work on this food section of our homepage okay so let's go back to our index.psp so to go to homepage which is index.php and here we need to go to our food menu section so this is food menu section and here we will do same thing as we did in our category section so let's remove uh all of this except one so what will what i will do is i will remove everything so food menu box so this is food main box opening of the food binding box closing out the food menu box one and then food menu box close food menu box this is food main box this is closing food menu box and let's go down opening food menu box closing food menu box and then this is opening food main box and this is closing food wine box okay so deep clear fix and let's remove all the spaces here and then here we have food menu box and closing food main box okay so we are left with only one food main box so let's save it go back to our browser and if i refresh it we only have one foodman box okay so let's go back and here now we will work on displaying the foods from database okay so for that we will use psp open php close and then here uh first thing we'll do is uh add the comment getting foods from database that are active and featured feature okay so and then here we create sql query query so dollar sql2 i'm creating sql 2 because we have created sql here so this will be sql 2 and then query will be select all from f r o m table underscore food where i will add where active is equals to yes and sorry and feature is equals to yes and we will only display limit six okay so we'll display only six so active is equal to s and the feature is equal to years limit six that's it now execute the query execute the query so here i'll create dollar raise to is equals to my sq sorry my sq l i mysqli underscore query and then dollar con and there will pass dollar sql sql2 that's it and then we'll count the rows count rows so dollar count 2 is equals to my sqli underscore now i'm underscore rules and here we'll pass dollar raise to and then we will check whether category food available or not check weather food of i label or not sorry or not here we will check uh so if dollar count two is greater than zero that means food available else else uh food not available and we will display the message so echo and here i will create a div div and let's give the class is equals to error and here we will say food not available a b a i already available that's it and here inside the count two when food is available we will use while uh loop to display all the food from database okay so let's create while loop while inside while loop will create dollar row to get all the data from database in row so dollar row is equals to we don't need this double quote mysq el i underscore faith underscore is and here will pass dollar uh rest two and then here we need to get all the values so here what we will get is title image name price and description and id okay so title price description image name and id so let's get those so i'll create dollar id is equals to dollar row and then id that's it and then dollar title is equals to dollar row and then this will be title and then dollar price is equals to dollar row price that's it and then we'll create or we will get dollar description yes c-r-i-p-t-i-n description is equal to dollar row description description and then we need to get image names so dollar image name is equals to dollar row and then image underscore name okay so and all of these uh row values are inside the row all of these are column name from our database table okay so these all are uh column name in our table so tvl food so they are this column name like id title description price image name category id etc okay so and we need uh this we need to add exact this inside our row okay so that's it now let's display those in our html tag for that we need to close the php and open the psp and between this ph opening and closing php uh we will add html tag okay so let's do that here i will cut this me food menu box starting and closing foot menu box from cut from here and paste inside here and i'll paste it here ctrl and v and let's push it inside to indent properly and push everything inside so that's it and it looks better and here we will display everything like title price description so let's display the title from database i'll remove this for title open php close php and then echo dollar title similarly we will display the price we will delete the numerical value we will and let dollar be here and we can open php close php and this display eco dollar price and similarly let's display the description as well so let's remove it and here upon php close php and eco dollar description okay so that's it now for our image we need to check whether image is available or not so here before image tag i will open psp close php and check so here i will add a comment check whether image available or not so if dollar image name is ghost is equals to blank that means image not available image not available else else image available so when image is not available we will display the message echo and i will create a div close deep div and here i will just add class is equals to error and i will call it as uh image net not available image not available that's it and here inside image available uh we will we need to display this html tag so i will again close php open php and here i will just cut it got this image dac from here got control nx and paste it here ctrl and v and we need to give the proper link so i will remove this url and i will open php close php and echo so it is site url and then now we need to go inside images slash food and then we need to give image name okay for php echo dollar image name that's it let's save it and go back to our browser and let's refresh and i think food not available so let's go back to our admin panel and let's go to food and our active is no but one of the foods active is yes i think we need to go and and it's active easiest but its feature is no so that's why and we have added sql query and in our sql query both of them needs to be yes so that's why we are not getting any images or any food so this is yes so both of them needs to be yes then only it will be displayed so for now i will update its value as yes update food yes update food let's go to our front end so this is our front end i'll refresh now we can see the image okay but image not available oh i don't know what's wrong i think uh we have a bug in our update food okay when i updated the food image is removed if i go to database if i go to database table food image is gone so when i update the food image is gone so we need to look on update food.psp okay so let's go back and let's go to update food so in admin section uh sorry in open our admin section and let's open update food which is update food i'll open update food and here when updating the food uh when updating the food we did not uh we are removing the image if image name is not is equals to blank so guys i have found the box so bug was after we checked like if image name is not is equals to blank then we forgot to add else so this is if so if we follow this line so this is the if and we also need to add else so here else and then here we need to add we need to give image name okay so this was not supplied so that was the error so when image name is not available that is when image name is not available or image so when image is not selected then we need to give the default image which is current image okay so let's save it let's go back to our browser and now let's uh again try it again so i'll update the foot for this right now choose the image choose this one and update food now we have an image and if i update food and if i turn it to know and update food now our image remains as it is okay so that was the error we forgot to add else condition when image is not available we added the else condition for when image is not selected but we did not added the default image value when image is not available okay so that was the error hope you fixed it so i will add the comment as well uh default image when image is not selected and here i will add a comment so this is default image when uh image is uh when button is not clicked so this is button is not clicked okay see click that's it let's save it and i'll close update food as well as update category and sometimes we face bugs and when you face the box don't panic so just try to focus on solving the error and we solved it successfully so let's go back and what we were all working on is we are working on displaying the food menu i refresh it our food is gone i'll go back to food and i'll update its featured status as well so featured is yes update food and if i go to home page and refresh now we can you can see our food but this is not the proper image we supplied so i will keep the proper images for this one so i'll give the proper image so i'll give the name as well best burger with pineapple or we can call it best burger and here we can give the details like base pineapple we can call it burger with ham pineapple pineapple and lots of this so this is the description similarly you can give any description and price i will give as four dollar and let's choose the image for that i will go to desktop and i will select uh menu burgers so i'll click select menu bulger open and choose both of them as yes and click on update food and this is also a burger okay so update for now this is image is updated so let's go to home page and our refresh and here now this is uh showing perfectly now similarly let's add couple of other other food items so i'll go to admin panel and i will add image on this and i'll also give the proper name so update food and here i'll give dumpling s especial s-p-e-c-i-n-c-i-a-l chicken dumpling with mountains herbs with herbs from mountains okay so let's get dumplings and let's give it as five dollar and then choose image and here i'll copy menu momo well meanwhile minimomo and this is not burger this is momo and active also yes update food and here i'll refresh and now you can see dumplings and burger okay so dumplings and burgers let's display another one as well so for this i will change the update food and i will uh give it as this is pizza so i'll call it what should we call it smoky bbq pizza [Music] best firewood pizza in town and you can add more details as well but now i don't have any details so i'll give six dollar choose image this will be uh menu pizza where is main menu pizza active will also be yes and i'll click on update food now we have three food items so i'll go to our home page refresh it now here you can see our three of the foods like dumplings burger smoky bbq pizza okay so this is how we can display uh or hide food menu so if i go to here and if i want uh it uh if i do not want it to show in home page then i will just turn feature as no so if i turn feature as no it won't be displayed in our home page okay so it won't be displayed in our homepage and similar as our category space we also need to display the foods in our food space so in this page we will display all the foods that are active so if we see if this food are active then this will be displayed uh here but if they are not active then this will this won't then the food won't be displayed in this foods page as well as in our home page okay so let's work on our force page so i'll go to our code view and i'll open foots.psp now minimize admin folder and i will open foods page where is food space this is our fourth page and here what we need to do is we can remove all the food menu box and we'll also we will only display one food menu box so i will remove this food menu box food menu box food menu box all the food menu box remove all the food main box and up to where up to here before clear fix and only leave one food menu box so this is the food menu box and this is clear fix and here we will uh display the food from database okay and display the food that are active and this time we do not need the food that are featured because this is separate page we are on home page on home page we display the food that are active as well as featured okay so i'll open php and here i will add a category a comment display foods that are uh active okay so i'll create sql code query dollar sql is equals to uh select all from tbl underscore food where active is equals to yes and we do not need to use limit keyword because we will be displaying all the food and here we need to execute the query execute the query so dollar race is equals to mysql i underscore queue uer by query and here we'll pass dollar connection and then dollar sql that's it and then we need to count the rules count rules to check whether uh foods are available or not so dollar count is equals to my sqli underscore num underscore rules and here i'll pass dollar raise that's it and let's check weather check whether uh the food are available abili available or not so if count is greater than zero that means foods uh available available so here we will get all the foods and display in our html else else we can display the message so food not available api label available and echo i will create a division div and then give class class is equals to error and here we will see food not found okay that's it now let's work when food is available we will use while loop to display all the foods from database so i will create dollar row as well ctrl z dollar row is equals to minus qli underscore fetch underscore as such so this will get all the uh data in a row format so i'll pass dollar raise and curly braces and this is not ros this is row row and here we will get the values so get the values like id so dollar id is goes to dollar row and then id and then we need to get title is equals to dollar row and then title and then dollar description description is equals to dollar row description yes cr iption description price we also need price and image name so dollar p r i c price is equal to dollar row and here i will pass price and then we will get dollar uh image name is equals to dollar row image name image underscore name okay so that's it now let's display all of these details in our html so i'll close sorry i will close the php open the psp and between this we will display our force in html okay so i will just copy this menu box from here i'll cut it ctrl and x and paste it here ctrl v and then i will push this inside push it a little bit further now let's first display the title price and description and then we can display the image okay so i'll display the title first php echo dollar title and then let's display the price psp echo dollar price and then let's display the description so here psp echo dollar description that's it now let's work on displaying the image to display the image first we need to check whether image is available or not for that i will create php before image stack and here we will check whether image by level or not so if dollar image name is equal to is equals to empty that means m is not available else image available when image is not available will display the message so echo deep dipd so that's the ibd and here i will add a class is equals to error and here i will add the message like image not available available and when image is available we will display the image with image stack for that we will close php open psp and between this i will i will just cut this html tag so let's call the html tag paste it here i will paste it here and we will give the proper image url so php and then echo dollar not dollar site url this is constant and then we need to go inside images slash food slash we need to give image name so what echo dollar image name so that's it let's save and go back to our browser and let's refresh our first page and here you can see three foods so if we go to our food order admin panel so this is our food or by admin panel and we have three food so if i turn the active of this off here uh feature uh feature is no but we can see it in food menu but we cannot see in home page okay so when feature is off it won't be displayed on home mirror but it will be displayed on full space okay but it's uh but if it's active is no like this then it won't be displayed in full space as well okay so it won't be displayed on foot space as well and same will happen in any of this if it is its feature is yes but if it's active is no then it won't be displayed either on full space so this is not displayed on foot page and this will also not be displayed on home page so it won't so it won't be displayed on home page as well okay so like this we can either hide or display our foods okay now let's uh go to our home page and i will refresh it now now you can add more foods you can add up to six food uh in home page you can display six feature food and you can display three uh categories of the food okay so that's it guys and in the next episode we will work on displaying the foods based on this category and we will also work on searching the foods from here okay 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 till now then comment below i'll reply you as soon as possible okay so see you on next episode till then stay safe take care see you soon bye
Info
Channel: Vijay Thapa
Views: 24,608
Rating: undefined out of 5
Keywords: vijay thapa, software development, web development, programming courses, free courses, php, mysql, php tutorial for beginners full, learn php, food order website, food order website with php and mysql, connecting frontend to backend, how to connect frontend and backend with php, web development full course, php project with php, php master course, php and mysql for beginners, cms with php, admin panel with php
Id: GxCh9B0ZU6E
Channel Id: undefined
Length: 77min 16sec (4636 seconds)
Published: Fri Dec 04 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.