 Right, so hey guys and welcome back to another Python tutorial So as promised, this is part two of creating a college system using Python and MySQL. So in the last tutorial we did a admin account which was able to register students teachers and it was also able to delete any student or teacher account so in this tutorial we're going to go ahead and actually code a bit more and Code up our teacher account. So the user that already exists on the system as a teacher Can log in into their account and can mark or view the register. So let's first of all what we want to do is go ahead and Open up ZAM. So we're going to be Creating this project backward as I said before So let's open up ZAM. You need to make sure that you have ZAM installed already So do that if you haven't already also if you haven't watched part one of this tutorial It's going to be linked in the description. So I recommend you do that first So once you have done that what you want to do is click on start for Apache and start for MySQL Then click on the admin tab for MySQL and give it a moment to load up So we have to go ahead and create the databases we need before we actually do anything in today's tutorial So in the last tutorial we created a database called college Which had a database called users this table pretty much stored the teacher accounts and the student accounts So as you may see right now it is empty That's because there isn't any teacher or students accounts in here. So that's the main reason it's empty So what we want to do is also have another table called Attendance which is where the teachers are going to be marking registers. So Let's call this attendance Now obviously the system is not foolproof or by any means ready to be deployed It's just to kind of refresh our memories on how to use MySQL with Python and how to create a basic command line application So don't expect this to be Usable in any scenario. It's just a fun project that we're doing So we're gonna have four fields one's going to be ID Which is going to be an auto increment field which will do a plus one each time a new record is added Another one for username another one for the date of the register and lastly another field for status So this status is going to store whether the user was present absent or late cool, so let's go ahead and scroll to the right and Click on AI which is auto increment for our ID field the rest of the fields and don't need that So once we're done with that we need to go back change the username into work variable character same for the date and the same for the status as well Cool. So once you're done with that just mention the values over here I'm going to go with a max value available, which is 255 obviously. It's not good practice But just since this is just a chill tutorial I'm just going to go ahead and do that and then I'm going to click on go So once I'm done with that we should have a new table. Oh wait, that's the wrong button We can click on save actually Once I'm done with that We should have a new table called attendance with the following fields ID username date and status Cool. So we've done the back end ish now So we need to go ahead and create a front end using Python. So let's go ahead and open visual studio code and I should have my file from last time. Okay, let's see file open file Close this off Just I'm going to just quickly navigate to the file. I had coding a coded last time in the last tutorial Should be here somewhere There it is. Cool. So we go up to this code in the last tutorial And what you want to do is go into your function the main function right here And in the main function last time we coded our admin We created an authorization admin and an admin session function. So in this tutorial, we're going to be Creating the teacher login. So the teacher would be allowed to log in as well So let's get rid of this print statement for teacher login and instead we're going to type in authorize Teacher now obviously it's going to complain saying that this function doesn't exist But we're going to go ahead and create that function right now So whenever the user clicks on option two from our main menu, which is login as teacher The authorized teacher function will be wrong. So let's go ahead and create that function now, let's just do it above Authorize admin so authorize teacher and Then let's do what we want to do is go ahead and probably print a blank line just to make sure that We're leaving some space Print black line then we can do print teachers Login just so that the user knows what part of the application they own another black line and then we need to gather the username from the teacher username username and then we need to gather the password as well. So copy this line paste it down here and change username into Password What's all my typing today? Okay, and I'm changing username to password so that I can take the username and password input from the teacher Now once this password and username input has been taken, we're going to run a query to our database. So query Values equals username username and password. Now we're just creating we just created a variable right here called query values We're just going to store all the values that are going to be passed in our query So we're going to be using this variable in a moment once we create our query. So to run our query We had a object that was called command handler that we used in the first tutorial. So let's type in command handler to execute so that we can execute our query and then I'm going to say select Star and select everything Select star from our users tables that we had in the last tutorial. So select star from users where username equals percentage S because we are going to be using a string formatter and password equals percentage S and privilege equals In here now we want to type in We're going to be typing in teacher Because the privilege needs to be a teacher since we are logged in as a teacher. We can't just log in as a student So now we've said select star which means select everything from users where username is going to be passed as username and Password is going to be passed as the password input that we just gathered. Now at the end of this line What you want to do is type in comma and query Values so what that's going to do is going to pass the username and password in place of this Percentage S so that this query is complete. Okay. What did I do there? Somehow managed to come all the way down there for some reason. Okay, let's go ahead and find the function I was just coding. Okay, here it is So we just finished our command handler now once we're done We need to do an if statement. So we say if command handler dot row count is Less or equal to zero Which means if the results that are returned are pretty much zero or none. We say login Not recognized Else which means if it is greater we are going to print welcome Teacher just for now and then we're gonna replace this with a function for the teacher session later Let's just see if this works. So let's run this up quickly Now I'm gonna go back in my database to check if I have any accounts. So as you see right here It's blank. So if I try to log in right now, it's just gonna not let me log in So first of all, I'm gonna log in as an admin. So this is from last tutorial. So I'm gonna click on three Login as admin and I'm gonna type in admin Password and then I'm gonna register a new teacher. So I'm gonna press two teacher username is going to be your hand And password is going to be password, of course very secure. So your hand has been registered as a teacher I'm gonna go ahead and log out. So press five now I'm gonna back on my main menu so I can press two to log in as a teacher I'm gonna type in your hand and Password I'm going to type a password and as you see right here. It says welcome teacher So that means as recognize my username and password now if I go back to my database and refresh this As you see right here, it says your hand and password, which means we did When we run our query, it did return a result because there is an entry based on our query in here So now let's try and log in using a gibberish username and password I'm gonna log in as teacher again gibberish gibberish. It says log in not recognized. So that's working perfectly cool, so let's go ahead and close this off and Let's now change this from welcome teacher to teacher session So that's going to be a function we create now obviously it's going to complain because that function doesn't exist But in the teacher session the teacher is going to have their very own menu where they can mark the register view all registers they have marked in the in the past and Log out cool. So as I as you may have noticed is pretty simple what we're doing right here So just to keep the tutorial short and simple So what I'm going to do is go ahead and create that function right above admin session and define teacher Session and now in here I'm going to print blank line. Okay, instead of doing all of this I'm going to go ahead and just copy it from here So I'm going to copy this Let's go and copy and then let's go ahead and paste So obviously there's a few things that change here. Now this admin menu is no longer an admin menu It's a teacher's menu because it's a teacher's login now in here. It needs to be first option is going to be mark student register second option is going to be view register and The last option of course is going to be log out since we can break through on the loop Then once we're done with that, we're gonna have to grab the user input. So user option equals input string Option option option and then we'll say if User option equals one Which is teachers Which means marking the register what we want to do is print a blank line and we're going to print Mark student register as like a little head up and then we need to do a command handler query So what we want to do first off is actually find out the names of the students that are on our users table So that we can later grab that name put it into our attendance table and then mark it as present or absent cool, so select Now we only need the username for my users table. So we're going to do select username from users where privilege equals Student because we only want students because we obviously we don't need to mark the register for any teacher accounts only student accounts So since we have that what we want to do next is store the reports into this variable called records equals command handler dot fetch All so what that's going to do is it's going to fetch all the records that are returned from this query right here Now obviously we're going to be needing a for loop to be displaying those records So before we do that, we need to know the date for which the user wants to store this record. So date equals input string date and then DD month and then year That's going to be the format. We're going to be requesting the user for the date They want to mark this register for and then we just do for records for record and records We want to do record equal string record dot replace We have to replace a single quote with a blank then we also need to replace the Coma with a blank we also need to replace the opening bracket with a blank and Lastly, we need to be replacing the closing brackets with a blank Now we're doing all this because when the record is returned It's returned as a tuple and then it has a bracket a comma and a closing bracket So when we do this replace right here, it's only going to return the name and none of the other stuff that we don't need So this is kind of essential to strip it down Cool. So now I'm going to make a comment here about what the different statuses are so present Absence and Let's do late. So that's the three statuses that the user can set for the different students Cool. So we're going to do status equals input string. So for each user that the Loop Print we need to set a status. So we're going to do status equals And then we're going to ask status for Then we're going to do a plus string So status for it's going to ask what student the status is being set for so it's going to tell the user What student is this status is going to be set for and then we're going to be presenting the options that are available PAML and then let's ask the user to give us an input Cool. So once that's done We need to set a new variable for query values because we are about to Insert all of these values into our attendance table. So string record is one of the First values and then we need date and then we also need status Which are just variables that we have here here and over here So we're just storing it all into this one variable called query value so that we can pass it into our insert query later so we do command handler.execute and Now we're going to run our insert query where we're going to insert all this information into our attendance table. So insert into attendance Then we need to mention what fields we are going to be inserting. We don't need to insert the ID So we just insert a username date and status and Then we need to be providing it with the actual values that are going to be entered into these fields So we need to type in values and then in here, we're just going to be passing in blank string Formatters because we're going to be passing in the values in the form of the variable we had called query values So the first first field is going to be The What's the it's going to be the name so the username variable that we have over here Second field is going to be the date variable that we have here and the last field is the status variable that we have Right here, which is going to be perfectly fine So once we're done with that we want to make sure that we're committing the changes by typing in database commits That will save and refresh all the changes and then lastly we print report Which is the name of the student that just got our marked and then marked as Plus the status cool So that's done now if I run this hopefully everything should work just fine and we should be able to mark the register for the student so let's run this up and If I go log in as teacher your hand Password now I've successfully logged in and I have my teacher's menu. So I'm going to go ahead and mark the register Now if you see right here is asking me for the date So I'm going to go ahead and put in today's date, which is I I believe 21st. Yeah, it is 21st of August 2020 and then It's okay So the reason why it hasn't shown me any students is because if I go back to my database here Go into users There is no students. So there's only one teacher that's been registered in here So we actually need to register a few students onto our system first in order to mark the register Otherwise, it just returns a blank Loop of nothing and then it returns us back to the menu. So what I'm going to do is I'm going to close this off Close this off from this again, and we're going to log in as admin to register a few students first. So let's log in as admin Password and then let's register students. So I'm going to go ahead and call my first student Matthew But the password of it doesn't matter because we're not going to be logging into the student account. Anyway, let's register another student Let's call him Josh Password gibberish is fine and one more student. Let's call it Mark Cool. So we've got now three students that are registered. We can confirm that by going ahead and refreshing our database So if you see right here, we have Matthew, Josh and Mark with which have been registered as students Now this had been done in the last tutorial, which is why I recommend watching it If you already have then that's perfect. Do you understand how this works? So now if I go ahead and log out by pressing five and return back to my main menu Uh, wait, what did I press? Oh, I pressed delete existing teacher by accident. Did I? Yeah, I pressed four by accident. So I'm going to go ahead and just Do that and then it says user not found. Let's press five this time and log out Cool. So now I'm back on my main menu. Let's log in as teacher Johan Password and now I can mark my student register. My date is 21st of August 2020 and Okay, so this time as well for some reason it hasn't done it. So let's Try and run this again. I'm not sure why run again So log in as teacher Johan password Okay, it's didn't happen the right one password Mark student register 21 20 That's weird It's not letting me for some weird reason. So I'm going to go ahead and debug. This seems like there's been a logical error somewhere So let's take a look. So for record in records, it should technically be in this right here. So select username from users where Privilege equals Oh, I see. So insert it's not privilege equal students It's privilege equal student because that's my typo right there Let's get rid of that. Make sure it's only student not students Because otherwise it's never going to return any results anyway Because we never register a student as students. We register them as a student. So singular. So two uh, Johan Password Now let's mark the register for the date 21st of august so 21st of august 2020 Cool, finally. So status for Matthew Um, and then it says present absent or late. So I'm going to go ahead and mark Matthew as present today Then it says Matthew has been marked as present then it moves on to the next status or the next student. So I'm going to mark josh as absent And we're going to mark mark As Let's go late Cool. So once all the students have been marked the This information is saved into the attendance database Now I can prove that by going into my database clicking on my attendance Table right here and as you see it says Matthew was present Josh was absent and mark was late and so and so date is shown as well So in our next function that we create or the next command that we create we need to um, Pretty much just show all these records. So the username date and the status which is going to be showing The user the register Cool. So let's go ahead and do that Um, so to do this we need an elif statement So we are going to quickly go ahead and do an elif statement. So we do What indent am I looking at? So it's right here. Cool So elif I can get caps off elif user option equals to You want to print a blank line And after that what I want to do is print reviewing all student registers Um, and then we're going to have to run our query. So command handler That executes a simple query of Select username Oops select username comma. We want also the date and we also want the status. Let's give this a bit of space We want the username date and status from the attendance table So we're pretty much selecting all the records and we're only grabbing the username date and status So we're telling it we don't want the id filled Cool. And now whatever results are grabbed. We're going to be storing them into reports Which is going to be command handler dot fetch all so it can fetch all the records Now, let's do a print statement and say displaying oops displaying all registers And then let's do a for loop. So for record and records Print and record so that should do the trick So now if I run this And we can we would actually be able to view the Registers if we did it correctly. So your hand password And I have a teacher's menu press 2 and as you see right here displaying all registers where Matthew on the 21st of august was present Josh on the 21st of august was absent and mark on the 21st of august was late Cool. So this function has been pretty successfully created as well Now lastly the logout function, which is the easiest of all what we need to do is type in go ahead and type in oops elef user option equals 3 which is for logout. We just break from this loop So when we break from this loop will be returned to our main loop from our main function And then that's the main menu. Cool. And then lastly we do else print no valid option was Selected just in case the user doesn't type 1 2 3 And anything outside that range. So let's um run this to see if we can actually log out Let's click on to your hand password Uh, okay, I didn't log in properly And then let's click on log out. So three And as you see right here, we have logged out and it says welcome to the quality system So guys that brings an end to today's tutorial. Hope you guys have enjoyed coding the teacher pits of this College management system. Hope you're looking forward to tomorrow's tutorial Which is going to be showing you how to finish this series and pretty much code the student dashboard So that the student can log in and do a few functions as well And if you guys would like to donate directly to the channel, you can do so by either becoming a patron on my patreon page Which is stated in the description Or you can purchase a super chat emoji or highlighted message when this video premiers Thank you guys once again for all the support that you guys have been showing me I'm really grateful for it Do consider joining the discord channel for a load of fun. Also follow up my socials It is great that you guys have been sharing my channel so much I would appreciate if you guys do the same because i'm trying to grow my channel And guys, I will see your beautiful faces in the next tutorial. Peace