3. Food Order Website with PHP and MySQL (Update/Delete Admin and Change Admin Password)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone i am visit hapa and welcome back to the new episode of our tutorial series today i am back with a new tutorial of food order website with php and mysql in the previous episode we have successfully added the functionality to add admin in database and we also displayed the admin in our manager and page today we will be working on update and deleting the admin as well as changing the password of admin so without further ado let's start our tutorial [Music] so let's continue working on our admin module and first i will work on deleting the admin because it is easier than uh arduino admin and it also takes less time so let's go back to our code editor so i am using visual studio code and this is our manage admin page and this is our ad admin page now i will create another page to delete uh the admin so i'll go to my project which is food order and inside the admin along with admin dot psg page we need to create delete admin dot php page okay so i'll click on new file icon and here i will create a new page the letter delete that's admin dot psp and here uh we won't be displaying uh any front end like uh we did on add php we will just uh process the data or delete the admin and redirect to the manage admin page so i will open with psp php and here i will write the steps that we will be doing to delete the admin so first step is to get the id of admin to be deleted then we need to create create sql query to delete admin uh this is step number two and step number three is to uh sorry three is to redirect redirect to uh manage admin page with message and the message can be either success or sorry either success or error the service and first first thing we need is to get the id so to get the id we need to go to manage admin page and here in our button we need to send the id so here is our button so here is our data admin page and here we need to send the id to our delete admin.psp page so here i will add a link so first we need to display is our home url which is inside our site url constant so this is a constant that we created inside constraints.php and it has our home url and after that uh we need to pass like i will check again so we have we have ended with slash so we do not need to pass the slash so admin slash and we are in we are sending this link to delete dash admin.psp so delete dash admin dot php hope you remember this so let's save it and i will go back to manage admin and refresh it and i will click on delete admin page and we are in our delete admin dot psp and we have not uh done we have not displayed anything so this is empty but if you are having a error like for for object not found error then your url is uh broken so you need to uh make your url uh like as shown here so this is our home url and we need to go inside the admin folder and inside that admin folder we have delete dash admin.psp and in this url we need to pass the id so i'll pass the id so id is equals to and we need to pass the value as well so our value will be echo and we have id here so our dollar id i'll pass the value so this will be our get variable so passing the value through url means this is a gate method passing the value through form like in our add method is a post method so this is post method whereas passing the value through url is get method okay so this is a get variable and we will uh and we will get the value of this id using dollar underscore get function okay so let's save it let's go back to our delete that's admin.psp and here we need to get the value so i will create a variable dollar id is equals to dollar underscore gate and our variable name is id that's it and here we can display the value and check whether we are getting the value or not so i'll refresh i will save it and go back to manage admin page and i'll refresh it and when you hover over the delete admin page you can also see the url at the bottom like this yes you can see we have one two and five we have treated the middle part while i was showing the database section so this is how we pass the value so if i click on one of this button then here you can see the value so this is one so if i click another one we have two and if i click the another one we have five so we are successfully passing the value and we are successfully getting the value in our delete admin dot p as page okay now we need to create the sql query and read the data from our database okay so i'll create the sql query for that i'll create a variable called sql and uh the query is delete from table name which is tvl underscore admin and we need to add where keyword where id is equals to dollar id that's it this id is column in our database table and this id is the value that we obtained from get variable okay after that we need to execute the query so execute the query here let's create a variable dollar risk and we will execute the query to execute the query we need to add my sqli underscore quality function and here we need to pass dollar con and dollar sql but dollar con we do not have dollar con uh because we have not like we have not included constant in this file so at the top we need to include the constraints to use uh this dollar coin because this dollar account variable is inside our constraints.php here we have dollarcon so we need to include uh our constructor.php file here so include include constants.php file here i n sorry include and here we will include our file so include file is inside our config so we need to get out of this admin page so to get out of the admin page uh when we use double dot or fully stop and then backslash and then we need to go inside our config folder this is config builder and inside that config folder we have constants dot php that's it so this will include our constraint.php file and we can use dollar connection and after this executing the query we need to check check whether the query executed uh successfully or not so here we'll check so if dollar raise is equal to is equals to true then query executed success fully and admin deleted but else failed to delete admin that's it now here uh we can display the message so i'll display the message echo admin deleted and here i'll display fail message echo fail to delete admin and semicolon let's save it and let's go back to our manage admin i'll refresh again and i'll click on delete button so this time i will delete this one i'll click on three admin admin deleted uh but we do not want to see the message here instead we want to redirect it it to home page and see the message in our home page so we will do that now at first let's go to our database and let's check the admin whereas the admin is deleted or not where is our database food order we can go to tvl admin and here we only have two data we have successfully deleted the one data and here also you can see one of the data is gone now let's uh uh redirect our page from delete admin dot php file and let's uh see the message in this manage admin section okay so i'll go back to our delete admin page and here i will just comment out this and then we will create assistant variable to display the message so create system variable to display vriab to this play message me ss message so dollar underscore session i'll create a session variable called delete and it will be like admin the a ltd successfully and then we need to redirect to our manager and paste so redirect to manage admin page so to redirect we'll use header function and header local host and then we need to pass our home url which is site site url and then admin slash manage does admin dot psp so this will redirect to our manage admin.psg file and here i think we have missed something oh here we do not have single quote close so that's is so i forgot to close the single quote here now i have added now we will uh comment out this message as well instead we will create session here also uh dollar system and i will give its name as delete so this and this is same and both success and failure message won't be set at the same time if the delete is success then this delete beta session variable will have this message but if we fail to delete then the delete session variable we have this message okay so that's why i have created same variable name for same session okay so don't be confused and here let's say failed to delete admin try again later and we need to redirect to our manager in page so i'll copy this one and paste it here okay so that's it now we have set the session but we need to display it in our manage admin page so i'll go back to manage admin and here we have add a session now let's check for our delete session as well so if it's set dollar underscore session and then delete then we will display the delete message so echo dollar underscore session delete and we need to onset as well onset dollar underscore session delete that's it now let's save it and let's go back to our browser let's refresh the browser and let's click on delete and check whether our uh delete page redirects to manage admin and displays the message or not so i'll click on delete button sorry we are not redirected so let's go back and check the error so here not here here we need to check localhost and then site url urban.php not localhost this is location location location let's save it and let's go back and let's go back and here you can see the message so message is showing successfully so i'll refresh once again and i will add an admin because we we only have one admin so i will add admin so we have added message so let's delete this one now i'll click on the admin so our date admin page has successfully redirected us to our manage admin page and we can also see the message which is administered successfully now i want to add some color to this message when we have success message let's display it in green and when we fail let's display this message in red okay so once again i will add couple of admin here so that we can check later so i'll add admin and so we have three admins now so i will add those color in our message for that i will create a css let's go back to our code editor and in our admin css here i will create uh some color for our error message so here i'll create a class called success success as well as and i'll give it color as color and here we'll give the color so let's go back to our browser and here i will go to flat by colors and the color theme we are using is i think chinese color palette and uh let's use this color to display the message for success i'll click on this copy and we'll use this color ctrl v and let's create another class for either so dot error and here i will call it as color and let's copy red color so i'll use this color copy and i'll paste it here ctrl v and save it and then let's go to delete that's admin.php and here is our message so here i'll add the css so i will create a div tag here so div and i will end the trade div tag here div this is ending deep so we need backslash as well and here i will add class is equals to and here you need to give some single quote because we have already used double quote here so we cannot use double quote again so instead of double quote we are using single quote here so here i will call it as success and here in either i will create a div sorry the dipd class is equals to error and here i will close the div that's it let's save it and let's go back to our browser and let's go back to our manage add-in page and here i refresh the manage admin page and to be sure i want to uh refresh the css file so i will right click and go to view page source and i will open css file so i'll click on this link and here i'll just refresh this page as well so just refresh this page to be 100 sure because sometimes due to cash some temporary files this does not refreshes and we cannot see the color but since we have refreshed now we can see the color because i can see the css classes here so it should work so let's refresh this page and i'll click contribute button so i'll click on delete button and here you can see the message in green color and administrator successfully if we have error message then we will see the message in red color okay so that's how you can use colors successfully for testing purpose i have deleted all the admins now i'll add the admin again so i'll click on admin and click here and admin uh but you cannot see uh this message in green please add the dip tag in our admin uh message as well okay so this is a classwork homework for you i'll add another admin as well so that's it guys we have successfully added the functionality to delete the admin now let's work on updating the admin uh to update the admin we need to display the admin in form like this so we will create a similar uh form like ad admin form but instead of this blank text block we will fill uh these text boxes with the details of selected admin so let's go back to our code view and let's create this update admin page so i'll go back and along with add admin and delete admin let's create a new file so i will click on this new file and here i will call it as update dash admin dot psp so here uh we need to include our menu and our footer file so i will uh open psp and here first thing i'll do is include and then we need to include partials slash menu dot php and another one is i will just copy this copy i will go down paste it here and instead of footer this will be instead of menu this will be footer.php that's it and here i will create a div of deep dot main content main content and inside that main content div we have wrapper so div div dot wrapper and that's it and inside this wrapper we have h1 tag and this will be update admin page okay let's save it and let's see uh how our admin update admin looks uh to see that uh let's add a link in our update admin button inside our managed as admin.psp file so i'll go to manage this admin.psp and here we need to add a link as we have added on our tweet that's admin.php file so here we need to display our site url first so eco site url and then we need to go inside admin and inside our update does admin dot php and we also need to pass the id so what id is equals to php eq echo dollar id that's it let's save it and then let's go back to our browser and let's refresh our manage add-in page and i'll click on update admin button so i'll click on update admin and here we can see our admin admin page so this is our update admin page now we need to create form and display the details of selected admin so i will create a form first and then we will get the detail of selected admin and display in that form okay so let's go back to our update admin page and after s1 tag here we need to create a form action we do not need to add anything we need to pass method sorry method is equals to this will be a post method because we are passing the value through form and here we will create table to align our input text perfectly so i will go back to ad admin and see the design so here we have created a form and table with 30 dbl 30 class for table and we have table row or tr and then td inside it okay and we also have to break tag after h1 so i will add two br after s1 pr and then we are sorry uh br we have to bear and after that we have form and here we need table and the class for our table is i will add space after form so the class is tbl dash 30 and after table we need dr inside the tl we will have td and first thing we have is uh let's see we have full name user name and password so first thing is full name and then we need to add a input tag so input type is text and then we need to pass name attribute name is equals to full underscore name and here we'll pass the value to display the current full name of that admin and let's create another row tr and here we will have td and here we'll pass we'll create a column for user name and let's create another column to display the username so input type is text and username and name will be sorry and name will be uh username and we also need to pass value that's it and let's go back to browser and see our ad admin page so add admin page we have full name username and password uh but in our update page we won't be displaying the password because password is encrypted and to encrypt the password we have used md5 uh function which is a one-way encryption that means we cannot decrypt the password so we won't update the password instead we will add another button and we will add a functionality to change the password okay so in update we will only be updating full name and username and in another page we will be changing the password so let's go back to our code view and here is our full name username and since we won't be updating the password i will add uh button after the username so tr and td and this will be goals pan and to call span 2 because we are merging 2 column we have 2 column in every row and inside it we will have uh submit button for that we use input tag input type is equals to submit and here our name will be submit and value will be update update admin adm i n and let's give the class for this button as btn dash secondary i don't know what uh class we gave for ad admin button so i'll go back here and here we have also given btn secondary so this will be consistent so let's go back to our browser and let's go back to our admin page and i will click on update admin and here we have our full name and username but we have not seen uh the current full name as well as current username so we need to work on that so let's work on getting uh the full name and username of current admin so let's go back to our code view and here uh before the form we will get the details of current admin so here i will open the php close the php again and between this php tag we will display uh the details of current admin and to get that uh details we need to get the id that we passed uh through our update admin button so we have passed the id in our update uh update admin button so let's get that id so i'll go to update admin dot php page and here first step is to get the id of selected admin and then second step will be create sql query to get the details that's it so here i'll get the id so dollar id is equals to dollar underscore gate because this is a gate method because we have passed the id through url so id and the variable name our git variable name is id that's it now here we need to create the sql query dollar sql is equals to select all from tbl underscore admin that's it and then we need to execute the query so execute the query to execute the query we will create a dollar risk variable and here we'll use mysqli underscore query function here we need to pass dollar con and dollar sql uh that's it and now we do not need to i include the constant.php because constraint.php is already included in our menu.php file so if i open the menu.psp here we have already included the constants and in our delete admin.plc we did not have uh that menu.psg menu.psg4 file that's why we needed to include the constraint.php so i'll click uh so i'll close the delete admin.psp and now let's check whether the query is executed or not so check whether the query is executed uh or not if dollar raise is equals h goes to true and then we will check whether whether the data is available or not so again here we need to check whether the data is available or not for that we need to count the rows so let's say dollar count is equal to my sq my sqli underscore now i'm underscore rws and here when you pass dollar result or dollar risk and here let's check whether we have data or not check uh with the uh we have admin data or not so let's say uh if dollar count is greater than 0 or let's see here uh i forgot to add the where keyword here we need to pass here keyword as well because we are getting the detail of specific admin so we need to check with where keyword where id is equals to dollar id that's it so this is our sql query and here since we are getting the value of one single id uh one single admin uh this count must be one so if dollar count is equal to is equal to one then only we will what we will get the details else we will redirect to manage admin page so let's redirect it to redirect we we use header and then location and here we need to pass site url admin slash managed as admin dot php and we need to close our code as well so that's it this this will redirect us to manage this admin.psg file and here let's say just for checking purpose i will display a message admin available we need to check this because sometimes some user will try to hack our system and if we do not check uh this then our system may stop working so i will give the demo of that so when you go back to our manage admin page admin page and click on let's say click on update admin so generally normal admin or normal user will just click on this button and see the page right and we have a message admin available as well but sometimes uh some admin or some user will try to pass the value from here so we have id is equals to nine and id is available and the admin is available but what will happen if i pass like 9 000 or 90 000 so if we did not check if we did not check like this then this would show the error but since we have checked whether admin is available or not this will when the admin is not available this will redirect us to home page okay so that's why we need to check this like this this is one sort of checking any kind of you can call it checking mechanism or you can call it adding a validation okay so let's go back and we have uh like checked whether the admin is available or not so i'll go i will select one admin and admin is available now let's display those details of the current admin okay so here instead of echo admin here we need to get the details so for that i will click create a dollar row variable and here we'll use mysqli under score fifths underscore a stock function and here we'll pass dollar raise and here we will create variables to save the uh username and full name of current admin so i'll call it as full name is equals to dollar row and here we need to pass the column name in our database table so our column name is full underscore name and username is dollar user name is equals to dollar row and username that's it let's save it and if we check the database and our columnar full underscore name is username so this is full underscore name and this is username so that's it now we can display this value in our uh this input field so we can display the value in our input field so uh let's display in our value property so in value i will create php and echo dollar full name and here in username will display php and dollar username that's it and let's save it and let's go back to browser and let's refresh it and here we can see the full name but we cannot see the username i think we have something wrong so what do we have dollar username dollar username dollar username echo i forgot echo here echo username let's refresh again so here we have our full name as well as dollar username now what we need to do is we need to update uh this uh value whenever we click on submit button so after the form or after the div i will create a form or i will create a php and check whether the button is click or not and whether the submit button is clicked or not and we will only update the admin when a submit button is clicked so check whether the submit button is clicked are not so if dollar underscore post and submit then echo sorry i have to close the bracket here echo button clicked that's it so let's save it let's go back to our browser and i'll refresh it and i think we have an either undefined deck submit if it's set we need to check whether it is set or not if it's it uh down underscore post submit then only we will text our refresh again now our warning is gone uh since we have not clicked the update button button we are we do not have any message so when i click on update button we have message button clicked and we only want to update that mean whenever update button is clicked okay so let's go back and i'll i will comment out it and along with our full name and username we also need to pass our id so here i will create an input tag along with submit button and this input tag will be input type will be hidden because we do not want to display uh the value in our update admin page like this but we want to pass the value as a post method okay so input type hidden name will be id and its value will be value is equals to php eco dollar id that's it so if i save it and refresh it i'll refresh like this and you cannot see the id textbook like this because this is hidden if i make it text and save it and refresh here you can see the id and value in a text box but we don't want to display the id like this so that's why i will call it i will make it hidden okay that's it let's save it and let's go back to our uh processing update form or update value now first thing we need to do is get all the value from form so get comment this is comment so get all the values from form to update so first thing i will get is dollar id is equal to dollar underscore post id and then i will get is dollar full name is equals to dollar underscore post full underscore name and then dollar username user name is equals to dollar underscore post this is the post variable because we are passing the value through form so this is a post method so username that's it let's save it and let's also uh echo or let's print whether our id full name and username is being passed correctly or not just for checking purpose i'll save it go back to the form i refresh the form and i will change the name like vg therefore and change the username vj tapa so a username uh do not have space whereas the full name has expressed i'll click update admin so here this is our id this is my id and this is my full name and this is my username so i'm getting all three values that's mean uh we are successfully passing the value from our form to our update processing okay so this is update processing section and we are processing the value on same page as a uh update admin page okay so now we need to create a sql query create a sql query q ui query to update create sql query to update admin so let's create an sql query so dollar sql is equals to update tbl underscore admin set and we need to set the value that has been changed so let's say set full underscore name is equals to dollar full name and then dollar username sorry username is equals to dollar user name and this is the database column name and this is the variable name that has our updated value so these are column names these are value from our form okay and at the end of the last column do not add comma okay and here i'll add space and then i'll press space and then press enter and where id is equals to dollar id because we only want to update uh this uh admin that is selected so that's why we need to use where keyword okay after that we need to execute the query execute the query now create dollar risk variable is equals to mysqli underscore query and here we need to pass download connection database connection and dollar sql and then check whether the query is executed or successfully or not check uh whether the query executed success fully or not so i will check if dollar raise is equal to is equals to true and then query executed and admin updated else failed to update admin so let's create a session variable and set the message so dollar underscore session update is equals to uh here we will pass admin admin updated successfully and let's add the css to display the color as well so diabetes class is equals to success and we need to close the div div so div class is equal to success and we need to redirect as well so redirect to manage admin page so header and then location site url and here we need to pass admin and manage that admin dot php that's it now we need to do the same uh in our else condition just the message will be different so i'll just query i'll just copy it copy header two dollar underscore session and i'll paste it here and this deep class will be error and we need to set fail message so fail to delete admin that's it and let's redirect it to manage this admin.psg file so let's save it and let's go to manage.admin.psp and display the message if the session is set so like delete we also need to check whether the session for update is set or not so if is it dollar underscore session update then we will display the message echo dollar underscore session update and then onset dollar system update that's it uh let's save it and let's go back to our browser and let's uh refresh this page cancel our go this way so let's go back to admin page so i will select this last one elena valenzuela so i'll create click on update admin and instead of this name i will give my name visit up and i'll change the username as well to visit tapa and i'll click on update admin admin updated successfully and here you can see my name which is busy tapa and username will change to visit up okay now let's add a last feature in this manage admin page which will be change password for our admin okay so i will add a button to change password and also create that functionality so let's go back to our code editor and in our manage admin page let's go back or let's go down and along with our update and delete button let's create another button so here i will create anchor tag and i will give its class to uh btn primary so let's give it as btn does bra i mean ry primary and let's call it as change change password that's it and let's save it by pressing ctrl ns i will save it by pressing ctrl ns let's go back to our browser let's refresh it and here we have button change password and update admin direct admin and this is change password now we need to create a page to change the password as well as uh add a link so first i will create a file inside this admin along with manage admin and all of these pages i'll create a file and here it will be update dash password.psp and let's save it and in our manage the manage that's admin.psp let's add a link so here it will be same like this so i will copy this and we also need to pass the id of selected admin so i will copy everything so instead of manage this or update that's admin.psg file this will be update dash not updates it is yes it is update password so this update i forgot the name of the file it was update and that's password.php so this is update that's password.php and we are passing the value of selected admin as well so that's it let's save it let's go back to our browser let's refresh it and i will go back to our update admin page not update admin we need to go back to update password page so this is our update password page here i will include our menu and footer so psp sorry php and then include include menu sorry we have menu inside partials for the prt ial partial slash menu dot psp and then i will include footer as well so i'll copy it ctrl alt ctrl c go back down ctrl v and instead of menu it will be footer okay now here we need to create a div for main content and inside this main content we have wrapper so div tip the drip wrapper so deep class wrapper deep class main content inside the main content we have deep class wrapper okay and after that we have s1 tag and this is like let's say change password and after s1 we need to add vr tag to br tag for better like spacing and here we will uh create a form to change the password of current admin okay so i'll save it let's go back and i'll refresh it and i click on change password and uh this is uh this will be the section where we will add a form to change the password okay so we can see the change password page that means our link is working perfectly if we have error like object not found error then please go back to your manage admin page and please correct your link uh in your change password button okay so you need to focus on this area so if everything is right then we can work on update as password so let's work on here so first thing i will do is create a form form because we need to change the password using post method using form so here we need to pass method method is equals to post and we are leaving action as blank because we are processing the uh form or we are changing or connecting with database and updating data on a same page that's why we are leaving it blank if we had created another form like update password action page uh to update all of these things and work with database then you need to give the link to that page okay and i have done that method or using another page to process the data in my another course which is creating a task manager app with php and mysql and if you want to check that i will put the link in the description for now let's work on this so i'll go back to form and here i will create a table to display the data so table and its class will be tbl 30 plus is equals to tbl that 30 and inside the table we will have tr and inside the tr we will have td and first column will be our old password so we will ask user uh to enter the old password this is not reset if we were working on uh reset password then we do not need old password okay so that is a separate things uh this is another thing okay so this is old password and then td and here we will create input type so input type it will be password password and its name will be that's the old password and value we don't need to display value we are just inputting the value so it will have placeholder plus folder is equals to full password and that's it tr td and then we will add a new password new password let's not call this old puzzle just call it current password current password this name is current password and new password and we will get another column td and here input type is equals to password name is equals to sorry not namespace name is equals to a new password and placeholder place holder is equals to new password we don't need semicolon i forgot that and last one will be like confirm password so we will ask the user to type the password two times so jd confirm password let's make it capital confirm password and we'll create input type input input type will be password and name is exerted name will be confirm underscore password and we will have placeholder as well this placeholder is equals to confirm password that's it now let's create a button uh to change the password and along with that uh button we will also need to pass the id tr and then td this will have cool span is equals to 2 because we are merging 2 columns and here we will create input type submit so input type will be submit and its name will be submit and value will be change password okay so that's it and password that's it i'm going to pass the id as well but we have not obtained the id from our manage admin page so here we need to get the id so i will create a psp so psp let's check if if a set dollar underscore gate id and then we will get the id so dollar id is equal to dollar on this we get id that's it and we'll pass this id along in this form as well so i'll get input type hidden here input type is equals to hidden and let's call it name name is equals to id and will pass value value is equals to psp eco dollar id that's it let's save it and let's uh view the form so here we have current password new password and current password and let's give the css for our button as well so this is beauty and secondary so this is our input button uh give class is equals to bit unders secondary let's save it and let's refresh it so refreshing it so here we have current password so let's change the name of placeholder as well this is current password current password so here this is current password new password and confirm password so uh since this is admin panel admin can change the password of anyone so uh in common sense uh this is not necessary because admin can change the password of anyone without knowing the current password of the current person but i want to uh but this feature can be add added uh when the user personal user have his or her own profile section and in that profile section they we can implement this but for normal user it's okay if we do not have current password but i wanted to show you the feature with along with the current password as well so that you can later uh add this feature whenever the individual or logged in admin has their own profile and they want to change their profile password only okay so i have added extra feature for that so let's work on this so let's work on current password for that i need to create an admin uh with a password that i can remember so i'll create an admin and i'll give full admin full name as administrator administrator i will give its username as admin and i will also give his password as admin and i'll click on add admin so we have admin with ad administrator and admin and its password is admin okay because if i do not know the current password then i can change the password so that's why i created the new admin so i'll go to change password and we'll work on this so we only change the password whenever this button is clicked so we need to check that so here i will create a psp and check check away the the submit button is clicked as not if is set dollar underscore post and then submit then echo clicked just for checking purpose and this is not double slash save it and let's refresh the page and i'll click on change password button and bottom is click and then only will process our data so first step is to get get the data from form and then second step is to check whether the user with current id and password exist not then we need to also check check whether the current or new password password and confirm password match or not and then only finally update change password password if all above is true okay so we'll do this so let's go to the first section which is getting data from form so first thing i will get is id so dollar underscore post id and then dollar re anti current password is equals to dollar underscore post underscore password and our password is always encrypted so we will use md5 to encrypt the password and then we will get new password dollar new password is equals to md five dollar underscore post a new underscore password and then dollar confirm underscore password is equals to md5 dollar underscore post confirm underscore pastor okay so that's it this is how we get the form and all of these dollar underscore post name should be matched with this name this input type name input type name current password new password confirm password current password new password and control password so first thing we need to check is whether the current id and current password exist in our database or not so for that we need to create a sql query ql is equals to select select a strict from tbl underscore admin where where id is equals to dollar id and and password is equals to dollar uh sorry which one is this current password so this is our sql query and if you see the difference we have single quote in we for password value but we do not have a single code for id because id is an integer uh variable or an id has integer value so it do not need a single quote but password is a string value or where can so it needs single quote okay now we need to execute the query so let's use the query dollar raise is equals to my sql my sqli underscore crazy and here we need to pass dollar connection and dollar sql if dollar raise is because this goes true and then we need to check whether data is available or not so for that i will create dollar count is equal to my sqli underscore nom underscore rules and here we'll pass dollars race and [Music] if dollar count is is equal to is equals to 1 which is there will only be one user there will only be one user whose id and password match because even if the password is same they won't have another id so there will only have one id with one password okay so that's why we are checking uh for one that means user exists and password can be changed but if is it's not equal to one then user does not like this does not exist user doesn't like this set message and redirect so i will set a message dollar underscore session i will call it as user not found and is equals to i'll display the message user not found found and let's give a div as well and class is equals to error let's close the div that's it so let's check uh for that i will uh call it echo and i'll call it as i'll give message as user found and let's save it and let's go to our manage admin page not manage admin so when uh we have an error or when user is not found then we can display the message on manage admin page okay so let's go to manager and page let's redirect to my certain page so i'll go here and along with this update message let's display the if it's a dollar underscore session user not found then eco dollar underscore session user not found and then unseat onset dollar underscore session user not as found so this message will be displayed whenever like we did on previous thing whenever someone tries to add the id uh with no user and tries to pass the value like i will do form filler and change the password sorry it's not redirecting because we have not redirected or i think we have not redirected oh so we have said the message but we have not redirected here we need to redirect the user so radia is direct the user so header and then location dot site url uh admins less manage this admin dot php that's it let's save it and then i'll go back and i'll go to home admin and here you can see the message because uh previously we had not redirected now let's see again so i will add uh id where user is not available so i will please i will give the id and press enter so that this id is set for now now i will try to fill the form and i click and change password and it redirects it because user with that id and password did not match so we are getting user not found message okay so this is uh validation or this is checking mechanism whether the user exists or not okay now here now we have to work on updating the password of the user so we can remove this message uh let's check whether this works or not so i'll go here and i will add the current password and i will type confirm password change password and user is found so when we do not add extra things then we can find the user but when you try to add a different value let's uh say let's add some password which have no which we have not set and check it as well and so user is not found because our password and id did not mess so we need to match the id of the user as well as current password for now okay and if you had not added this current password uh if you if you if you only have new password and confirm password then you do not need this step or you do not need need to hold this step okay you can always you can only do the step inside this if method okay so now here we will check whether whether the new password and confirm password match or not so here we need to check so let's check it if dollar new password is equals to is equals to dollar confirm password then only we will update the password else we will redirect to manage admin is with error message okay so for that i will just copy this message and use it okay so i'll go here and paste it and tab it and i'll change the system variable name as not match password not match okay sorry password not mess let's change the message password did not match okay so now let's save it and let's go back and let's try this one so i'll refresh it and i will type call and password and this should be right and i will type new password something and i will type confirm password sorry we have not uh like added the or display the system message in our manager in page so here we need to display the system so if we said dollar underscore system and here our password not match and then here we need to display using echo dollar underscore system pwd not match and then we need to unseat dollar underscore session pwd not match that's it save it go back and i'll click on change password here you can see the message password dot match and uh if the password is met let's display the message so i will just for checking purpose i will call it password match just for checking purpose we will comment out later so let's go back and let's refresh and i will type the current password here you can type one two three four five uh one two three four five and change the password password match so when the password is matched then only we will uh update the password okay so let's work on updating the password so now we can update the password so for that we need to create another sql query we have already created sql query here now we need to create another sql query and we need to create this so since we are on our same code block we cannot create another variable with same sql query so let's create sql 2 so i'll call it dollar sql 2 and we'll call it's sql query so update tbl underscore admin and then we need to pass it and here we will set the password password is equals to dollar new password that's it and we do not need comma space and press enter and where id is equals to dollar id that's it and then we need to execute the query query so dollar rds 2 is equals to my sqli underscore query dollar connection database connection can be same and we are using dollar sql too that's it and then check whether the query is executed or not check whether the query executed or not let's check if dollar raise are before not for dollar raise to is equals is equals to true then we will display message else display is our message for message i will use a same system variable and redirection because we will be because we will be redirecting to a manager in page so i'll copy it i will paste here ctrl v i will indent it and here instead of i will change the session name this will be change csng change pwd password and this is not either this is success and i will call it password change successfully that's it and i'll copy this and i will paste it here this is the success message and this is either and this is error and we'll have error message to change password sorry password that's it and then here uh we don't need to change anything let's save it and let's go back to our manage admin and here we need to display the message session message if the session is set so if it's set dollar underscore session uh what was our system name system was changed password so if it says csmg change that's pwd password then we will display the message and we will onset it so equal dollar underscore session change that's pwd and onset dollar underscore session change pwd so that's it let's add semicolon let's save it by pressing ctrl and s let's go back to our update password page and i will refresh it and let's type the current password and let's type the new password two and two we need to type the password correct password in both new password and confirm password and in call and password you know type call and password let's click and save change password password change successfully so that means our change password functionality is working perfectly and to check this mechanism or to check this functionality we will uh create a login functionality in next episode and then we will check this functionality okay so thanks so much for watching uh we have successfully added the functionality to delete the admin update the admin and change password in this tutorial for our admin module and in the next episode we will create authentication or login system for our food order website using plc program language and mysql till then stay safe take care and i'll see you on next tutorial see you soon bye you
Info
Channel: Vijay Thapa
Views: 36,629
Rating: undefined out of 5
Keywords: vijay thapa, web development, programming courses, free courses, php, mysql, php for beginners, php project, complete php project tutorial, food order website, online food ordering system in php, food order website with php, how to make food ordering website in php, CRUD, add, update, change password in php, web development with php and mysql, php and mysql tutorial for beginners, php and mysql project on online food ordering system, online courses, learn php, php course
Id: 1Aik3MWJTTo
Channel Id: undefined
Length: 85min 27sec (5127 seconds)
Published: Thu Nov 12 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.