2. Food Order Website with PHP and MySQL (Add and Display Admins)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone i am tapa and welcome back to the new episode of our tutorial series on food order website with php and mysql in the previous episode we have successfully designed admin panel and also broken down uh the different parts like menu and footer into reusable parts called partials and in this episode we will work on adding actual functionality and we will start with admin module so without further ado let's start our tutorial [Music] now let's work on our admin module so here is our manage admin page and in this page what i want to do is i want to display all the admins that has been added on database uh so we will display this admin on table so here i will create a table and make a place where we can display our admins and we'll also add buttons to uh go to our ad admin page as well as update and delete admin page okay right now we have not added a functionality to add up admin page so we cannot get the admin from database we will just make a design and later when we add the functionality to ad admin in our database then we will get all the admin from our database okay so let's go to our code view and let's design the table where we can display our admins so i'll go to my visual studio code and here this is our managed admin dot plc page we created earlier now after this h1 tag i will go down and here i will create a table table and here inside table i will create a row table row t r and inside that table row i need table heading so i will create th and i will copy this and paste multiple times ctrl c ctrl v ctrl v ctrl v so first one will be serial number and second one will be full name and third one will be email or username so let's see let's see our database i'll go to my phpmyadmin and here this is our database food order and let's uh select tvl admin and let's select structure and here we have id full name username and password and password will be encrypted so we do not need to display the password in our manage admin page we will only display full name username and serial number so full name and another one is user uh name and the last one will be actions in this actions we will add buttons like update admin and delete admin so let's save it and let's go to our browser and let's refresh the manage admin page so i will replace it so here we have our table but we do not have any borders so we will add borders using css but for now i will add a td as well we have added table heading now let's add table data so i will end our row here and create another table row tr and inside this tr we will add td td and uh let's copy how many table heading we have one two three four so we'll need to create four columns so one two three four and this one will be this is serial number so it will be one full name let's give as uh v as a white that's a pa this is just a dummy data later when we add the functionality to add uh the admin then we will display from database okay so admin username will be let's say visa tapa and here in last column which is actions here we'll have buttons like update admin admin and another will be delete admin button so we'll have two buttons so for now i'll just write the text and later we will create a button and display here so save it by pressing ctrl n s and refresh it so we have refreshed and we have the data and it is not that good not that appealing so let's make the design better so now let's uh design or apply some css in our table so first thing i want to do is i want to make uh this table in manage section like manage admin or manage category or manage food or manage order sections i want uh the tables on this section to be full width so let's add let's create a css to make that table of full width so here i will create a class called tbl that's full and here let's give the width as 100 percent let's save it and let's add this class inside our table so go to manage admin dot php and this is our table here let's give a class this is tbl dash full let's save it and let's refresh so uh our table is a full width now let's uh add some space uh between the rows and also let's add some border uh in our table heading so i will target our th of our table so let's go to admin.css and here i will target table tr and that's and i will give a border bottom border bottom bo sorry border bottom of one pixel solid black and let's save it by pressing ctrl n s and let's go back to our browser and let's refresh and we have a nice border here now uh let's add some space uh for our heading as well so i'll go back and here i will add a padding padding of one percent i think that will be good let's save it and let's go back to our browser and let's refresh it now we have nice space now let's align our text in left side so i will add text align property takes this line will be left and let's save it let's go back to browser let's refresh it now text is on left side now let's add some space in our td or table data as well so i will target now td so this will be table trtd and it's a padding we will add padding one percent and let's save it and let's refresh now we have nice space in our td as well so let's add multiple uh td so i'll go back to our manage admin dot plc page and i will just copy this tr let's copy up to starting tier ending tier copy and paste after this tr and tr so this is one this will be two this is just for dummy data okay so let's save it and let's refresh and here it is uh and it looks pretty nice so now let's create our button and for this complete cms or content management system or add-in panel i will create three different type of button or but three buttons of different colors first one will be btn primary uh which will be of blue color and another one will be btn secondary i think it will be of green color and third one will be btn danger it will be of red color okay so and that danger will be used for delete admin so let's create css for our button so i'll go to admin.css and here after table let's create css for our button so i'll give a class that's btn that's primary and here i will give background color first background background color background color and it will be blue but i want a good blue color so i'll go to flat ui colors and here i'll go to this one and we are using chinese color palette i think so i'll go to this palette and we will let's use uh this two color so on hover i will add this color and on normal i will show this color so let's copy first this one this is copied and go back to our background color so i'll paste it here background color let's save it and let's create a button so i'll go to manage addon page and this btn primary let's add a button after manage admin so if we go to our admin panel so this is manage admin heading and this is the table and between heading and table i will create a button to add admin so let's go back to our manage admin and between heading and table i will create a button so i will create a comment and button to add admin and here i will create a anchor tag and its link will be its destination will be default link so i have give a hash our pound sign and inside that i will call it as add admin okay and here i will give a class and its class will be btn dash primary and let's save it and let's go to our browser and let's see how it looks i'll refresh the browser and here it uh its background is applied successfully but i need some space uh between manage admin and table so after uh manage admin here i will add a break br tag and after this anchor tag i will add another br and let's save it and let's refresh the browser and let's see so we have space after this one and after angle tag as well can we add more br after the anchor tag copy paste paste save it and let's refresh oh yeah we have some nice space i will add some more beer above as well so here also i will add some br save it and let's refresh it i think that's okay but we need to make this button a little bit bigger and we also need to change the color of the text so let's go back to our css and here in our btn primary i will add padding padding of one percent let's save it and let's refresh now the button looks bigger i think that's okay and let's change the color of the text so let's change its color to white and save it and refresh it's white and it's nice now let's remove uh this underline as well so i will remove it so text text decoration none save it and refresh it and underline is also gone and let's make it let's make the test text a little bold so i'll go with font weight bold and save it and let's refresh it okay that looks nice now let's uh add a darker blue color so right now we have added this as a background color and when we hover over the button i want it to change to this color so i will add a hover color as well so down this i'll get another class btn dash primary and colon and we'll add uh hover and when it is over i need to change its background color so i'll just copy it paste it i will just change the color value so let's go back and let's copy it i'll copy and paste it here and let's save it and let's refresh it let's refresh the page and let's see so whenever we hover our color of the button changed so that's it now let's uh create other two buttons for btn secondary and btn danger so i will just copy all of this btn primary copy btm primary and btn hover and let's go down the btn primary hover and i will paste it here and i will call it btn secondary and this will also be btn secondary so that's it so this is b10 primary b10 primary hover b10 secondary b10 secondary hover we just need to change the color okay so for btn secondary i will make green color so this this will be the primary one primary means uh when it's not over and this will be the over color so let's add on btn secondary control v just uh be careful uh when you just select and paste you might have double hash sign so that should not be there so let's save it and let's refresh but we have not added a bit and secondary anywhere so let's go to manage admin and let's create button so i will call it i will create anchor tag here and this will be dummy link and here we need to give class class is equals to btn dash secondary and here we will have update admin and i will copy this again ctrl c and this will be delete admin so i'll paste it here and this will be delete admin and this will be btn danger let's save it and let's refresh the page so here we have a btn update update admin and its css is applied successfully now we need to change this over color as well so let's change its over color to darker green so i will copy this dark green let's go to advent.css btn secondary and button secondary hover and save it and let's refresh it repress our page so update admin and whenever we click over btn hover its color change and let's add a bit and danger color for beauty and danger so i will just copy btn secondary again and i'll paste below button secondary hover so this will be btn danger now beaten danger retain the arbiter danger and let's change the color to red so let's add this color so this will be the first one and let's paste it here ctrl v let's save it and let's refresh the page and here the css is applied successfully now we need to add hover color as well so i'll copy this one and let's go and change the bit endanger hover and remove this paste it here save it let's refresh it and when we hover its background color is changed i think uh the visibility for this lighter green is not that good so let's change the color uh to black whenever it's not hovered so let's go to btn secondary not bit and secondary over btn secondary and let's change this color to black let's save it and let's refresh and let's refresh so just be careful it is on btn secondary okay so save it and refresh now it's visible and i think that's perfect and its background color is changed background color is change and everything is working fine so let's copy this button and add it on another row as well so let's delete this and let's paste over here and similarly over here and let's save it by pressing ctrl ns let's go back to our manage admin and i will refresh it so it looks better now okay so uh let's copy and paste all of these things in another other pages as well because there will be table on all of these pages so i'll just copy uh everything from this br to table end so this is table end so i'll copy and open manage category and paste after heading paste it here and this will be add category and save it and don't worry about the column name we will change when we will work on these modules so i'll refresh and i'll go to category and here you can see manage category and add category and all of this column name will be changed whenever we will work on this section okay so now let's go to manage food and let's paste below heading as well paste here and it will be add food okay and save it let's refresh let's go to food and here you can see add food managed food add food and let's go to order as well so i'll open order and after the heading i'll paste it here as well and here we do not need a button for add order and let's save it i think i will remove this br as well because order will be made by customers and so admin won't be making any order so we don't need add order button so let's refresh go to order and here we have our table so that's it now let's continue working on admin section uh we have beautifully designed the table for manage admin section or all of the managed part so now let's close all of these pages and we'll focus on manage admin only now we need to uh add or create another page which is ad admin so let's create that page so here i will just minimize these parcels so along with index or manage admin page here we need to create another page called add dash admin dot php and here we need to add uh our menu and footer and main content area but first i will link this ad admin in our ad button so here is our ad admin button and here i will give the name a to that page which is add dash admin.psp sp and let's save it and let's refresh the page and when we click on admin it should go to our new admin page so whenever i click it goes to add-on page we have not added in that page so it is blank but if you are seeing any kind of error like object not found then you have an error in link so just uh go here and give the filename that we just created which is add admin.php okay and this is not the right way to give the link to the file we need to give full uh link and we will add the full link uh when we create uh constants so when we have to create constraint where we will be saving a home url like www.something.com and we'll save database credentials like database username database password database name etc so we will create that page and later we will add full link to go to any pages okay for now that's it's fine so let's save it and hope your ad admin button is working perfectly so now let's work on our ad admin page so first thing we need is include the menu so i will open php and close php and between here i will add include and we have a menu inside our partial so sorry partials slash menu dot psp and semicolon end so that's it i will save it and let's go to our browser let's refresh each now you can see the menu and this is one way to include the menu there are four different ways uh one is include another one is include ones another one is required and another one is required once so i have talked uh everything all of these things about all of this thing in detail in my uh another php course which is create task manager with php so if you have uh if you don't have much experience in php i would recommend that course but if you want to know more about include include ones require requirements then please do some research on them or and i also link to some articles from my side as well so go down the description and click and read about those as well so all of those things are little bit different but they do similar stuff but they are somewhat different as well okay so for now just focus on include and after that we also need footer so i will include footer as well include partial slash footer.php and our semicolon let's save it let's refresh it and we have footer as well now we need to add main section which is main content so here i will create a div and inside that we need to add class class of main content and inside this main content division we need to add another div called wrapper its class will be wrapper and inside this wrapper we can create a heading so i'll create s1 and it will be like add sorry capslock add admin and let's save it and let's go back to our browser and let's refresh it and here we have add admin and in this page we will create forms where admin can input the details and save the admin in database so let's uh create form here so after the heading i will create form form and here uh this is action so for now leave the action blank and here we need to specify method as well method is equals to post we have two different methods uh one is post and another one is get uh post is whenever we submit our uh value through form then we need to add it as post and the value from post are passed uh hidden past without displaying on browser if it is a gate method then the value passed from form will be displayed on browser as well okay so we need to add its method as post and to design our form better i will use table so here inside the form i will create a table so after the form i will create a table table and inside the table i will create row tr and inside the tr we will have td and first one we need is let's see our database design so first thing we need is full name and then username and then password so this will be full name and then another column will be here we will add our input tag so input input input type will be text and its name will be sorry not name space on the name name is equals to let's give it full underscore name it should be uh if um the name is of two words like full and name then it should be connected either with underscore or minus or hyphen sign it should not be two different words okay and let's save it and let's refresh our page here so whenever we refresh so here we have full name and our input field and here i want to so display like enter your name or example full name so i'll give it a placeholder place placeholder is equals to like enter use name let's save it and let's refresh it and here you can see the display the message when uh whenever i type my name it will disappear but whenever it's empty it will be displayed and don't worry about the design we need to specify its width as well so if you remember we have created a table with full width now we need to create another table with like 30 width so i will call it uh t bl and 30 because it will be of width of 30 percent so width of 30 percent save it so tbl30 just remember and let's go to our admin page and here is our table and here we will add that class tbl that 30 let's save it and let's refresh the page now it's on uh same line and it's okay it's fine so this is the very minimalist design we won't be focusing more on design because uh this course is completely for psp so we'll focus more on php rather than on design but if you want to learn design part then you can check my web design course and i'll add the link to that course in the description below and it is a free course so feel free to check out and learn some web design using html and css okay so now let's add another input field which is username and other will be password so i will go back and here after this tr ends we need to create another tr and inside this tr we will add td and this one will be user name and then another td td and here let's put the td in different line and it will be more clear so that's it and here we need to create input tag input type will be text and let's say name is equals to username and we need placeholder sorry here we forgot our double quote so username then place folder is equals to user your username and let's save it and let's refresh the page and here we have full name and username and last one will be password so let's create another tr tr td and this will be password and td input is input type always this is a password and we need to give its type as password yes sorry pss word password and then its name will be name will also be password password and this folder will be your password just save it and let's refresh the browser so here we have our full name username and password so the difference between input type text so this is also input type text this is also input type text but this is input type password so the difference between input type text and input type password is when input type takes when input type is text you can see that value whenever input type is password then its value is hidden so okay so this is the difference between put type text and input type password so after this we need to add button so i'll get another tr and td and i will merge two columns 6 uls gold span is equals to 2 and here i will add a button and i will give its class as btn secondary okay so this will be input type will be submit and its name will be name sorry name is equals to submit and let's give its value value is equals to add admin so that's it and we need to give class as well so here class is equals to let's keep it as btn secondary let's save it let's refresh the page and here we have our btn and admin button okay so it's not that great but it's fine and whenever we click it submits the page and let's add some space after the heading so let's go to heading and here i will add br and another br tag let's save it and let's refresh it i'll refresh like this and we have nice space here and this is it so if you want you can uh make this input text more beautiful but for now i will go with this we are not focusing more on design in this course so now we need to work on uh adding the data into our database so whenever we click on this add admin paste we need to process all of this data from this form and submit or insert in the database and if you have checked my previous course on creating task manager with php and mysql then in that course i have created different page to process uh the data from form but in this course i will uh show you how you can process the value from form and insert in the database in a same page so here we will be processing the data so if you leave the action value as empty then it will process the form in same page so let's go after the footer so after footer here i will open php php and close php and here we will process the value from i'll add a comment proc process the value from form and save it in data base so here we need to check whether the form is submitted or not so to check the form we will use this property use the value of name property here this is a button and whenever this button is clicked then only we will process the form so let's check check check with the button is clicked or not let's say submit button submit button and let's check and here we'll check if is set dollar underscore post and we will check our submit button so here i will tell you about instead function this is the uh set function of php and this function check whether a certain property is set or not and in this condition we are checking whether the value on submit uh submit this is input type submit whether the value on submit is passed through post method or not so this will this reset function will check whether the value on submit uh is passed using post method or not okay and if the value is passed then button clicked else button not click so let's display the message just for checking purpose so echo clicked i'll copy it i will paste down here and button not clicked and let's go to our browser and let's refresh it right now you can see button not clicked and whenever i click on this button it's button clicked okay so we will only process whenever the button is clicked and let's refresh again and when button is not click we do not need to display this message so we will remove this else condition so let's remove this else concentration we don't need this we only need this section okay so here i will comment out this message we don't need to display message instead we need to process the data from our form so first thing uh first step of processing the data is to get the data from our form so get the data from form and since we are passing the value using post method we will use post method to obtain the value from that form so first thing we need to get the value from is full name so i will create a variable dollar full underscore name is equals to dollar underscore post and we need to call the value from form with its name so it is i think full name sorry full name this value and a value on input type text name should be same so we are accessing the value using this name property so this name should be same here so we have access the value full name and we can check the value here so let's check whether the value is obtained from form or not so i'll add echo let's save it and i'll go back and i'll refresh it and here i will type my name for now and whenever i click admin so here you can see my name so we are successfully getting the value from our form so i will remove echo now similarly we need to get username and password so i'll get dollar user name is equals to dollar underscore dollar underscore post and it is sorry username and after that we need to get password so dollar password is equals to dollar underscore post password password and let's check whether these are same in our form forms input name property or not so this is username and here is username and this is password and here we have password so that's it and to verify whether we are obtaining the value or not you we can you can add echo and go back to our form and check manually so here username submit so we are getting the value and remove the echo and let's check for password let's add echo on password save it go back here refresh the page and in password type pss download password and add admin so this is password so we are getting all the values in our form processing so now let's remove the echo and now the next step is to create our sql query to save the data into database so sql query to save the data into database so this is our first step one is to get the data from from and second step is to create the sql query to insert the data into database so i'll create a variable here dollar sql is equal to uh [Music] insert into tbl underscore admi n this is our table name and we'll use set query set and let's pass the value in our column okay so if we check our database we have full name username and password and you do not need to pass the value for id because it is auto increment and it is primary so it will automatically submit the id so we need to pass value for full name username and password so here we need to specify the column so full underscore name is equals to and single quote dollar full name and then username is equals to dollar username and then password is equals to dollar password so that's it and one common mistake that every beginner makes is put putting the comma at the end of the query so you don't need to put the comma at the end of the column you need to put whenever you need to add another column like after the full name we have come after the username we have comma but this is the last column so we don't need to add the comma at the end of coulomb and this is on the left side we have column name in our database so these are the column names and all the column names are on the left side and on the right side we have value from our form so these are the value from our form and these are the column name in our database table okay so this is our sql query now we can uh see our sql query as well echo dollar sql and we can see our sql query as well so i will refresh the page and i will add the value and username password and when i click on admin we can see the sql query it is insert into tbr underscore admin set full name is equals to bjthappa username is equals to admin and password is equals to admin and we need to encrypt our password so let's encrypt our password so here we will use md5 so md5 is an encryption function and it is a one-way encryption that means we cannot decrypt uh the encrypted password so here i will give a comment uh [Music] password ption with md5 so that's it so it will this md5 will encrypt our password so i have added a small bracket or parenthesis and close the small bracket or parenthesis don't forget that now again let's go to our browser and let's refresh it and let's fill the form and password i will add a d m i n and let's click on admin now here you can see our password is encrypted okay and this is our sql query and if you do not know the basic of databases like sql query for insert update delete average function average uh count sum max main etc then i have a course for beginners in database i'll put the link in the description so that you can check those whenever you are free and you can learn some basic stuff of database as well so this is the query but we are not executing the query we need to execute the query and insert it in our database so let's execute the query now so we have uh created the sql query to insert into database but here in third step we need to execute query and save data in database base okay so here we need to create let's create a bit another variable called dollar risk the dollar risk means result so this will hold uh true or false value if the query is executed successfully then this rest value will be true and if query failed to execute then the value of raise will be false okay so the query to execute the sql query is mysql i underscore query and our die mysqli underscore error that's it so we are using mysqli instead of mysql this is the improved version of mysql so we'll be using mysqli and this query will execute our sql query so here we need to power database connection like dollar con and dollar sql and here so this will execute our query and if the query is executed successfully then we will move on but if the query is failed to execute then we need to step uh other process so here we might have other process so we will not go into another process if it failed to execute the query and we will stop here and we will display the message so this mysqli underscore error will display the message and this die will stop for the process okay so that's it and we have sql dollar sql but we do not have the database connection so we need to create the data on base connection as well so here we can create database connection dollar con is equals to mysqli underscore it's connect and we need to give our local host host llc lss localhost and another one is we need to give a username and password for our database user and same as this we will also or die mysql i underscore error so what this line of code will do is uh this will this function mysql mysqli connect will try to connect to our database using our credentials this is the host of our database host which is localhost for us and this is the username and password for db user and by default our db username is root and password is blank but whenever you are making the website or web project live then you need to give your database username and database password here okay and if it failed to connect then we will stop the process and will display the error message and this is database connection i will comment out here database connection and this will connect the database but we also need to select the database so db underscore select is equal to mysqli underscore select underscore db and here we need to give our database name db a name and also we need to die if our database name is not match so underscore error selecting database so here we will give the database name and we also pass we also need to pass database connection dollar con and db name so our database name is so let's go to our browser and let's see our database name so our database name is food dash order so we'll give that name so our database name is food dash order so that's it so here we need to connect database and then select the database and then only execute the query for now i want to execute the query so let's see whether our database is connected or not so i will comment our execution query execution code save it and let's go back to our manage admin or add admin and refresh the add admin page i will input or i will enter the value in input fields using a plugin called form filler this is a plugin you can get for chrome or firefox and it will fill the form automatically i won't fill the form manually so i'll just click and it will fills the form i'll click on add admin and we do not have any error that means our database is connected successfully and our database is selected successfully so let's try i will add random password and let's refresh the page uh input data and admin now here you can see the error which means database is not connected successfully access denied means failed to connect to our database so our username and password should be correct okay and i'll refresh again fill the form and add admin and we have successfully connected and selected database so let's mess up with database name so if i give the database name and again fill the form and click on admin mysqli underscore error so this also gives the error because our database name is not correct okay so you need to be careful while passing your uh database username database password and database name okay and uh we need to connect and select database every time we uh pass the value pass or obtain the value from database or whenever we need to manipulate database and this line of code will repeat again and again uh and it also messes up with security because we are displaying the username password and database name in every uh page we create like we will have ad admin add category add food update delete etc all of the pages this line of code will be repeated again and again and the value remains same value won't be changing value remains the same but the code repeats again and again so what we can do is we can create a separate file uh to connect database and select database and we can just call like we called our menu and footer so let's create an uh separate file called config and we will store this code in separate files which will be secure as well as we will be following dry pattern which is don't repeat yourself so we need to be productive guys so i will minimize admin and along with admin css and images i will create another folder here so along with inside the food order here we i will create i will create a folder and it will be called config and this is with this is not inside admin uh this is in a root label so this is inside food order so along with css images and admin we have config page and here i will create uh cons t a and ts constraints dot psp file and here we will add those code php and here we will add this code so i will just got this code here and paste inside constraints.php i'll just remove it and here we can also add these credentials like username password and db name using constant so here we will create constant create constraint to store none repeating values here we will create constant because our database name database username and database password will be same for our whole project it won't change based on different pages so we'll create constant and when the value is changing we create variable when the value remains same we create constant okay so let's create a constant so to create constant we need to use define keyword define and then we need to give the name so the name will be so first i will give its name as localhost i'll create a a constant for host a local sd host and to give the name of constant you need to use all capital letter so constant are named with capital letter whereas variable uh named with small letters so keep that in your mind so this is a constant so it is on capital letter now let's pass the value value will be the close localhost that's it so here now we will pass this constant okay so localhost and this will automatically get the value from this constant similarly let's create another constant define sorry this will be db underscore username and db username is root and here we will pass that constant this is db underscore username and then we will pass define db underscore password and its value is empty because we have not passed any value here so this will be empty and here we will pass our constant which is d b underscore password that's it now here we need to pass database name so let's create another constant which is defined this is d b underscore name and our db name is for dash order and here we will pass our db name db underscore name so that's it now here it looks more clear and more professional as well so whenever we need to change or change database username or database password or database name we will change here and it will be changed all over the place okay so if we had not created this file and just uh added uh like previous like here then we need whenever we needed to change the database username or database name then we need to change in every pages where we added those two line of code so this is more perfect uh this is the right way to do that so this also follows the dry pattern don't repeat yourself and this is manageable code this is the way of writing manageable code okay it might not matter when your project is small but when you have like a project with thousands of pages then it's really difficult to find the blog or make some changes but uh writing code like this will make your life a lot easier so you need to follow always follow best practices while learning programming okay so we have created this page but we have not added this page like we added menu or footer in our manage admin or admin page we have uh added a menu like this we have added uh the menu in every pages like this now we also need to add uh this construct.php page in all of our page and to do that uh what we can do is you can either add another include in ad admin or any pages you want like this like you can include and then call constants.php but this is also not perfect because you need to copy this code in all of the pages as well right we won't be doing that instead what we will do it we will paste uh we will include that constants file in our menu so here we have our menu so we will include that code in menu and it will be applied in all of our pages okay because we have uh included menu in all of the pages so we will add the constant file in menu and it will be applied in all of the all of other pages okay so hope you understand if you have confusion understanding this then please comment below i will try to make you understand as easily as possible so what we have done is we have created constant page and we want to include that constant page in all of our page and if you did like we have done for menu.psp then we can do that as well but we will need to include that constant in all of the pages but we have already included menu.php why don't we add that uh constant.php and menu.psv file and it will apply in all of our pages so that's it now i will go to main.php and here i will open php at the top and here we will include our constraints.php so this is inside our so this is inside our menu.php inside our parcels and we are working on add admin dot pay at add admin dot php page so we are on this label admin so to connect our constant.psp we need to get out of this admin folder because we are working on admin or manage.php manage admin dot php page so to get out of that admin folder we need to add double quote and that we need to get inside config folders and then add add not add sorry and then constants dot php so that's it let's save it and let's go to our address folder not folder our page and refresh the page and our page is working successfully and we do not have any error that means we have included our page successfully if you see any error like if i remove this two dot and save it and refresh it you will see like error because we have not properly added our config.php page so you need to add double quote and uh don't be confused guys we just we are working on we are on add advantage page and to connect our construct.psp we need to get out of add admin page and then come to our config folder so this will get out of admin folder and we need to get inside config folder and then connect our constant php so that's it if you are having any difficulty on following this tutorial uh because of different parcels and different pages then i would recommend you to watch my previous course which is creating task manager app with php and mysql and then coming back to this course okay so this is a little bit more advanced than that course so that was the very very beginner level course and this is a little bit more advanced than that course and we will i will create another course which will be more advanced than this course okay so if you follow these three course then you will learn basic and inter interbit level php programming so you will learn to manage all the file system and you will learn to uh code in php using object oriented programming as well so in the next code i will create object oriented programming course so for now we have uh included our constant and it is applied on all of the pages so automatically because we have included menu in all of the pages our database connection part is already applied in all of the pages okay so this is our constraint.php so if you want to verify whether your constant is working perfectly or not now you can again mess with like db password and save it and if i refresh the page we should see an error so here we have error which is mysqli error so that is because i messed up with tv password so tv password is this so this verifies that we have successfully connected our database and selected our database in all of the pages now we do not need to worry about our database connection and selection anymore we have connected once and we will just use this variable and we won't be writing this code ever in this project okay guys so let's close this constant file let's close menu now the hurdle of writing the code again and again to connect and select database is gone so our one of the problem or two line of code are removed for a for forever in upcoming pages so that's it now we need to work on this now it will work perfectly because we have already uh created database connection it will work now and let's add comment here so i will add this is step number three executing query and saving data into database after that we will check for is check whether the data is inserted or not or we can call it whether the where it is executed or not and display i repeat message okay so let's check if dollar raise is equal to is equals to true then data inserted else fail to insert data so for now let's display the message with echo data inserted and else echo fail to insert data okay now let's save it and let's go back to our browser let's refresh it and let's go to our admin add admin page and let's enter some value and let's click on admin so here we can see the message which is data inserted and let's go to our database let's refresh the database and let's see whether the data is inserted or not so i'll go on browse and here you can see our data in inserted successfully let's try again so i will refresh it and i will fill the form and i'll click on add admin data inserted let's refresh the database again and here we have our two data so we have successfully inserted the data in database but we want to display the message here not here so uh let's remove it we won't be using this method to ins uh to display the message instead we will use session to display the message okay so session is like a variable but it works across the pages and it will only hold the value as long as the browser is open so if you want to know more about the session then please do some research or do some google you will find a lot about the session okay so i try to make you understand in easy way about session session is like a variable that can be accessible among different pages but the value will last or value will be stored as long as our browser is open that's it now here we need to use the session we need to create a session variable and store the message but uh to do that we need to start the session first so let's go to our constant.psp and i will start the session so at the top here i will start the session start session i'm starting the session here because uh when i add the or start the session here then it will be uh and then session will be started everywhere because this page is included in all of the pages okay so system underscore start and this will start our season that's it now we can use the session so let's go to our ad admin and here i will create a session where available create a variable to display message and let's create a variable dollar underscore system i will give a variable name as add and is equals to and here we need to give the value [Music] add mean added successfully that's it and after this we need to redirect our page as well so redirect page so redirect we will use header function header and then location location and we will use uh site url constant we have not created site url let's create a site url constant as well so along with localhostdb username and tv password in constant.psp we need to create a constant another constant for our home url you can call it home url or site url i will call it site url and its value sorry its value will be our home page so let's go to our browser and our home page is this local slash food order so this is our home page so i'll go here then so this is our homepage so i will copy it and i will paste it here that's it this will be our site url so we will call site url and it will get the value for us and here in location we need to add that constant so i will concatenate so to concatenate in php we use dot or period sign so this will concatenate uh string value so this is a string value now we are concatenating our constant site url and site url gives site url gives the value of our home url but we need to redirect this page to redirect page to manage admin admin so this is our ad admin page and whenever we successfully add admin then i want it to redirect it to our manage admin page so we will direct it to manage admin page so this is our home url and to go to our manage admin we need to go to admin slash manage this admin dot psp that's it let's save it so i will make you try to make you understand you might be confused but i will try to make you understand so i'll go to the page so this is my manage admin so this url is our site url or home url so this is our home url and to go to manage admin page we need to add other things that is admin folder and then manage admin.psp so we just added this value after site url so this is home url and then admin folder and then manage this admin dot php okay so that's it so here is our session variable session message and here is our redirection and we need to do same for our else condition so let's copy i will copy it and i'll paste it here so this will manage we need to but if it failed to insert the data whenever we fail to insert the data we will be redirecting the page in our ad admin page so here we will redirect to add admin so this will be add admin and message will be fail to add admin so that's it let's save it and let's refresh the page we have created the variable to display the message and we have redirect the page on both if and else condition on successful and fail but we need to display the message as well so to display the message let's go to our manage admin so here we will be displaying the message and i will display the message at the top so here i want to display the message so before the button so i will need to open php here open php and then close php and here we will check whether the variable or whether the message is set or not we to do that we will use state function if we said dollar underscore session and system message or session variable is add so i'll put it down here so variable is add because we have system variable add and if the value is set then only we will display the message so echo dollar underscore session add that's it now let's save it and let's refresh the page and let's add the value and let's create add admin and here you can see the value uh you can see the message so i will add br again i'll add br here one beer break before the button let's add the air tag and let's refresh the page oh sorry i need to add another br so let's remove one beer from here and let's refresh now you can see the message let's add another beer as well here we won't focus on designing part okay so you can see the message here but the message is displayed forever it did not disappear so we need to uh display the message one time only and after it displayed the message one time we need to remove the message as well so to do that what we'll do is unseat the session onset dollar underscore session and it will be add so this is removing system message and this is displaying system message okay so please uh look at the session thing so please do some research on session about onset is set dollar on the suggestion so this will be homework for you guys so let's go to our page and let's refresh and if we refresh the message it disappeared i will click again i will fill the form i'll add message is displayed but if i refresh the page the message is gone so that's what we need we have displayed the message on manage admin page but we also need to display the message and add admin whenever we fail to add the admin okay so we need to display the message and add admin as well so at the top of the page after this ad admin uh i will open the psp here also and check whether the session is set or not if is it double underscore session and and then we need to display the session so echo dollar underscore session add and then we also need to remove the session so onset dollar underscore session add so that's it so second i will add the comment checking whether the session is set or not display system message a set and remove session message so that's it so this is added in page this is manage admin page and the message on manage admin will be shown when we successfully add the admin but on ad admin page message will be shown when we fail to add the admin okay so that's it let's check it once again i'll refresh the page i will fill the form click on add admin our message is displayed successfully because our admin is added successfully and whenever we refresh another once again the message is gone so let's check our database and our refresh the database and we have added uh five different admin so far so this is it guys we have successfully added the functionality to add admin in database now let's display uh those admin in our table so uh let's go to our manage admin page and now we will display all of those admin all of those admin that has been added in database in this table so after the tr of our heading here i will display the admin from database so i'll open the php and here i will uh write sql code to get all the admin from database so dollar sql is equals to select all from tvl underscore admin that's it and then we need to i'll add the comment as well we need to get all admin and then we need to execute the query so dollar raise is equal to my sqli underscore query and here we need to pass dollar database connection and we need to pass dollar sql that's it and check check whether the database whether the query is executed or not if dollar risk is equals to true if the query is executed then only we will [Music] process further so first thing i need to do is count rows that is if the data is inserted then we have multiple rows value value with multiple rows if we do not have any admin then this there won't be any rows so we need to check whether we have data in database or not so to do that we count the rows controls to check whether we have data in database or not so dollar rows is equals to mysql i underscore norm underscore rows so this function will check whether we have this function will get the number of rows we have in database and we need to pass dollar risk value i will add the comment function to get all the rows in database so let's check check the number of rows if dollar rows is greater than 0 that means we have data in database else else we do not have data in database okay so if we have data in database we need to get all the data from database and we need to display in our table for that we will use while loop while loop dollar rows so we need to use a dollar rows here so i will call it dollar count this will be dollar count dollar counts dollar count now we need to use dollar rules dollar rules is equal to my sqli fetch underscore sss race so here we will this code will like this mysqli underscore fetch unless stock will get all the rows from database and stored in our dollar rows rose variable and here we will use while loop to get all the data from database and this while loop will run as long as we have data in our database okay so using while loop while loop to get all the data from database and while loop will execute will run as long as we have data in database that's it now we need to get individual data so let's get get individual data that is so first thing we need is our id dollar id is equal to dollar rows and then column name which is id and then dollar username dollar full name name and dollar rose full name and then dollar username username is go to dollar rose username we don't need to get password because we won't be displaying password because that is encrypted value so this is the variable we created and this is the column name in our database so our column name database is id full name and username so these are the column names so these are the column names and these are the variable and will display this value in our table okay so here we will display the values in our table so here i will break the php so i will write the ps i will write the html code to display uh this value uh for that i will need to break the php i break the php and then again restart the php here so i broke the php here i started the php here and between this i will write html code to display all of those values so here we will be displaying all those admin so i will copy this tr copy and i will paste between this ending php and starting php i have done this just to write the html code so this is html part and here instead of our dummy value we need to now use this value from database okay so here i will i can start the php and the php and here i will call echo dollar full name okay and here uh we will call it php echo dollar username username so that's it now let's save it and let's remove other tr we can remove all of this sorry we can remove all this tr remove only tr okay so this is the ending tier so i'll remove all of this tr and we have we only have single tr but we are using while loop so it will display all the data all the admin from database okay so let's save it let's go to our browser so we have our five admins so let's refresh it sorry we have error mysqli underscore num rules i think let's go to our num rows so we have an error on line 44 and the error is raised is equals to true here we need to have double equal to sign so this is if we have double equal to then this is comparison operator this is assign assignment operator so this means uh the value of dollar raised will be true but if we have double equals to then only we are comparing the value so we need dollar double equals to sign okay so what we have on add underscore admin so let's check and do we need to check dollar resource yeah we added the comparison successfully but here i forgot and i added the single equal to sign so that was the error now let's refresh again now here you can see all the admins and username and full name and here we have one on one so let's display the id for now so here i will display the id psp echo dollar id that's it small psp sorry it was a caps lock psp and a small echo you see it so echo let's save it and i'll refresh it so here you can see the id but the problem is whenever you delete one of the items in the middle so if i go and here delete the three number and refresh it it breaks the change now we have one two four and five and since the id are auto increment and they are generated automatically it won't generate it it won't generate the id that has been created uh once what it means is the id will only be created only once so how can we solve this issue to solve this issue what we can do is uh we can create a variable before the while loop so this is why loop so i will create the variable before while loop and i will call dollar as end and assign its value as one and create a variable and assign the value so that's it and what we can do is we can go to inside go inside while loop and while displaying the id instead of widely while what we can do is display our variable dollar sn so i will save it and i'll refresh it but what it's doing is it's displaying one so what we can do is we will add plus plus and it will increase uh the value of s n which is one every time it loops with one so if i replace it now it is one two three four five and it doesn't matter how many times i or how many times we delete the value it will be working perfectly so we have fixed the issue of serial number as well now what we have done successfully is we have displayed the value of all the admin that has been added in database successfully now uh next thing we need to do is we need to work on delete admin and audit update admin okay you
Info
Channel: Vijay Thapa
Views: 71,285
Rating: undefined out of 5
Keywords: vijay thapa, software development, web development, programming courses, free courses, php, mysql, php tutorial, php tutorial for beginners, php project, php project tutorial, complete php and mysql course from beginner to professional, php admin panel, crud, php crud operation using mysqli, web development full course, food order website, online food order system, online food ordering system in php, food order website with php and mysql, learn php, php course
Id: o-6cL61-uDw
Channel Id: undefined
Length: 94min 7sec (5647 seconds)
Published: Mon Nov 09 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.