 Hey guys, and welcome back to another PHP tutorial. So this video is just going to be a continuation of the last tutorial that I created, which was basically validating a form. So in this tutorial, we're going to go ahead and basically create a session page for the user, and we're going to design the session page in the next tutorial. So first of all, what you want to do is, like always, start your XAMP service and click on the Apache and SQL. And then what we want to do next is open our text editor and also the browser that you're going to be accessing your website through. If you guys haven't watched the first few tutorials, I really recommend you do, otherwise, this wouldn't make sense, because in the first few tutorials, I showed how to create a login and register website and then also design it. So without further ado, let's begin. So this is the stage that we reached last time along with validation. So I'm going to log in quickly using a, I'm just going to register a quick account. Test one. And then password is just going to be one. Register. Test one. Okay. So as you guys see right here, what happens when we log in is the information is transferred towards the link up here, and it says username equals test one. But instead of saying welcome test one, it says welcome admin. So I'm going to show you guys exactly how to transfer this information from up here to the page. Usually you'd use a session variable to do this. But in this tutorial, I'm just going to make it easy and show you how to use the get to get the information from the URL bar. So first of all, what you want to do is go onto your session page and clear the welcome admin. And then we're going to start a PHP script there. And we're also going to end it down there. So first of all, we're going to gather the username. So we're going to create a new variable called username and we're going to equals that to $get. And then we're going to say, so basically what this does is it gets anything that's already being posted through the URL bar up here. And then we need to tell it what we want to get. So we want to get username because that's what the, that's what it's called. And then we want to get the value of username. So we're just going to say get username. And then we close that. And then we're going to say for now echo username just to see if it works. Save that and quickly refresh. And as we see right here, guys, instead of saying welcome admin, it says test one. So we've successfully gathered the username of the person logging in. This is obviously going to change based on the person's username every time they log in. So yeah, that's how we do that. And then we're going to design this a bit better. So we're going to say echo center h1 wages calculator dashboard. And then close that as well. And so again, we're going to echo this out and we're going to say center. Let's just use a h3, I guess, which stands for header three. It's just going to be a bit smaller in size than the header one. And then in there, we're going to say welcome username and we refresh this page quickly. We have something that would look similar to a dashboard. Obviously, we haven't done the styling yet, but we can just copy and paste it over from our login and register if we've got one. So we just copy the h1 tag from the style, copy that, create a new style tag up here after the heading. And then I'm just going to paste it right here. And then we do the same. We're going to add comma h2. And as you see right here, the first one is obviously done, but the second one hasn't for some reason, or obviously it's h3. So we do h3, but we can't do that because if you guys notice the font size is way too big. So we're going to have to do a separate one for h3. Unfortunately, create a new one. We can copy these over and we're just going to change the font size for the h3. So it's a bit smaller or we can just leave on default by clearing out save and refresh. And it looks pretty decent so far. We're just going to go ahead and add a borderline. So we're going to say, first of all, we add a bit of padding. Padding equals 15 pixels. Refresh. And then we're going to do border, bottom, red. Actually we go solid, red, two pixels. And we have a clean looking interface which separates the, obviously the upper websites from the information that's going to be displayed down here. So if we go ahead and go back and if we change the username to, let's say, something more realistic like, use the one at gmail.com and password will be 123 register. Use the one at gmail.com 123 login. And as you see right here, it's obviously changing the name based on the user that's logged in, which is perfect for now. So we have the basic information that we need from there. If you wanted to, you could also collect other information from the user like the age, blah, blah, blah, and then save that to the database and then retrieve their information through the database. So if we go onto the database, I'll show you exactly what I mean. PHP My Admin. We go to POS. Actually, it's the wrong one. Trial system. Users. And then obviously in here we haven't got much apart from the username, password, and their ID. But let's say for example we saved their age or let's say they had like a bio line that they would use or their wage that we're calculating later, we'd save it in a different table and then we could obviously retrieve that information and display it down here. That's what I'm going to be showing you further on. So what we want to do next is create a new form. Actually, we're going to create different buttons that the user is going to be able to use. First of all, we create a login button so it can obviously go back. We do that simply by typing in, we just create a new form basically form method equals post. We create one of the input tags. Type equals submit. Value equal logout. And that's about it for now. So if you see right here we have a logout button that's been created. So now we're just going to do a trigger function. So if is it and we also need to give it a name. So name equals logout. So if is it dollar post. So if this gets posted, which is logout, every time the button is pressed, obviously the logout thing is going to get posted. Then we want to redirect the user to the homepage. So we're just going to use the meta tag that we used before. I'm just going to quickly copy and paste that. I'll echo this. Go here, paste it there. Equip content URL session.php. So instead of doing session.php all we have to do is change that to index.php. Refresh the page. If okay. So we have to add an else as well obviously. So else, echo none. Continue. 934. Obviously we had to end the one before. So yeah. We click on logout now. It should have redirected us to the login page, but for some reason it hasn't. Let's take a look. Index.php. I'm assuming I'm missing a... Yeah, there we go. So I was missing like a single quote there, which was causing the problem. So I'm going to log in again, which was user1.junior.com. One, two, three. And if we click on the logout button, the user successfully logged out. Now, further ahead, we're going to allow the user to like go ahead with some of the functions on the website. So some of the different web... I'm just going to create a basic function to show you how to retrieve information from a database and display it. So for that, we're going to have to gather some user information. So I'm going to go ahead and log in. Let me test one. Okay. And then we create a new button down here. That's pretty simple. Now we just copy and paste the same thing over and we change the values. So I'm going to call this one account details. Okay. And then we call this details. Okay. So we're going to refresh the page quickly. And we have another button that says account details. So on this button, what's going to happen is the user should be able to register his account details onto the website once he's created the account. And if the account details already exist in the database, they use... Obviously, he wouldn't input them again, but he should be able to view them as well. So if this is account details, then we move on to the next one, which is going to be a new form. So I'm just going to copy the form obviously again because I don't want to waste time. Let me just copy and paste that again. And then we go ahead and change this to text because we want a text entry. Value equals none because we don't need a value there. Name would be... Let's call this full name. Then we move on. And I'm just going to copy and paste this one again because it's easier text. And the name... Obviously, we need the text holder. Actually, it's called placeholder. Equals full name. And then I just copy that and paste it down here. So the next thing we're going to gather from the user is going to be their age. And it will change to age obviously. Then we copy this, paste it over again. And the last thing we're going to gather for now is the wage that the user is going to get paid. So my basic idea about this system is basically like a wage calculator. So the user should be able to calculate their wage. The concept so we can work on this website. Wage per hour, let's say. And that's all. And after that, we're going to do a submit button and the value of the submit button is going to be... Finish. And the name is going to be account details saved. So as you guys can see right here, if you refresh the page from scratch, nothing shows up. But when we click on the account details, we have like a little form showing up for us that we have to input. So now we have to go ahead in the database, create a new table for this user obviously. Or we could still use the same table if we'd like to, but it's always recommended to use a new table. So we're going to call the table account details. We're going to do full name, age. Actually this should go... Yeah, ID should go first. Always keep in mind full name, age, and then the wage obviously. So I'm just going to keep that as is. This to text, this to text, text. And I'm going to do the auto increment for the first one. So we have an auto incremented ID for every record that's saved. Now we go ahead, click on save. And we have a new table where we're going to save all these details from the form. So once we've gathered all these details, we're going to carry on and go and create another elseif for the asset. So if it's a dollar, if it's posting account details saved, then what we want to do is go ahead and gather all those details. So we're going to create new variables, so full name equals dollar post, full name. So what this is going to do is whatever details I've posted through this form, once the submit button is pressed, it's going to gather them and save them into these variables so we can later on go ahead and save them into the database. So we're going to gather the full name and age is obviously going to equal dollar post, age. And last one I'm just going to copy and paste because there's no point of typing again, wage. And then we just type in wage. And once that's done, we want to do a MySQL login. So we do MySQL connect. We type in the obviously run localhost. So we're going to type in localhost. We're logging in through the username root. And then we're going to leave this blank because I haven't set up a password yet. And then we're going to select the database. MySQL select database. The database name is trial system. Okay, then once that's done, we're going to write our first query. So MySQL query. First of all, what we want to do is run a query to check if the user has already saved details into the database or not. So how are we going to do that is, or actually what we could simply do is let the user save the information only once and we can do an edit function in a later tutorial if you guys request that. So we need to check if the username has already filled in this information. Obviously, you should be allowed only once to fill in the information in the database or it's going to be redundant data, which isn't a good thing. So how we do that is we say select start from account details where username or actually where full name. We have to, so just remember we had to do another field in here. So we're going to add another column for the username of the user. Username is going to be the username that's used to login. That's what we're going to use for reference purposes. So we're going to save that quickly. And we've amended another field in here called username. So we're going to say select start from account details where username equals username. So the username is obviously what we've gathered at the start right here. We're just going to gather that again just in case the variable gets lost. Save that here. And then we close that. We're going to do this as a request. And then we're going to call this result mysql.numberOfRose. So what this does is it calculates the amount of rows based on the query. And then request. This thing here there. So if there is any accounts based on any rows in here based on this information, on this query, it's going to display how many rows of information match this criteria. So if it's 1, then it's fine obviously. If it's greater than 1, there shouldn't be. So that should be what the concept is right here. So we say if result is greater than 1, then the user already obviously has the information saved. So if it's greater than 1, we should just display the information to the user. Else, we're going to register this information. Else, we're just going to write another query. And then we're going to say inserts into account details. Oops. Values. We're going to save the... Obviously, first we're going to do a blank because that's for ID. Then we're going to do the full name. Full name. Then we're going to do the age. And then we proceed on to the wage. And then last but not the least, the username. And then once that's done, we just echo out a paragraph and say user details have been saved successfully. Okay. And here, instead of saying anything, we're just going to echo out a paragraph and say user details already exist. Use edit button below to change details. Or actually, we'll just say use delete button to record new details. Okay. So if we now quickly go ahead and refresh this page. And if we do, go ahead and see here. We're going to create a full name, which is going to be user shorhan godino. We're going to type in an age, which is going to be like, let's say 22 for now. And wage is going to be 12 pounds an hour. Finish. User details have been saved successfully. My skewer of number rows and viewing is given. Okay. Let's just see if it saved anything. Well, it has because obviously the rows might have been zero, but there's been an error here as well. So let's take a look at the error. Select star form account details where the username equals possibly because of the missing quotes. We refresh. It's obviously saved twice now. Okay. That shouldn't really be happening. So if the result is greater than one. Yeah. Everything seems correct. I'm just going to echo the result to see what it's actually displaying out. Okay. Oh, now it's working correctly. So let me, let me just take a look. So if we delete these both, and let's start again. I'm going to register a new account. So it hasn't full name. 12. Finish. User details have been saved successfully. Okay. Now we go back to account details and finish. User details have been successfully saved again. Hmm. Okay. Let's try using greater than zero instead. And now we're going to go ahead and delete these. Okay. Now we go account details, register an account. Finish. User details are saved. And then we go account details again. Okay. That's perfect. So obviously once it's saved, now it's not allowing us to save it anymore. Based on that username obviously. So if we go ahead and type in account details, type in finish. It says user details already exists. Use delete button. And to create a new record. So now for the interesting part, we're going to display all the information from the database. So right here we're going to display all the information. So we write a new query for another request. So request one equals my sql query, select star from. We could actually just copy these, this one, because it's going to be the same query. So we're just selecting all the, every record that has the same username as the login session. And then we're going to change it up here. So instead of doing that, we're going to do result. Actually, the second line is going to be the same as well. We need to gather how many rows exist so that we can do a loop for it and then loop it around to gather as much information as it exists. And then result one will equal that. We do result two as well equals my sql query select. It's not going to be query. It's going to be my sql fetch rows fetch array. It's going to be my sql fetch array. And then the query that we're going to pass through for this is going to be request one. So basically what this is going to do is it's going to fetch all the information that is available in this and it's going to save it into result two. Before that we need to start a loop. And we're going to do in the loop is we're going to start a for loop. And then we just change the values and we say is greater than result one. So this loop is going to run as long as the I is equals the same amount as the rows that exist. So inside the loop we have to paste result two so that it can update as it goes. And then here we're going to display the information to the user as well. So we're going to do is echo full name. And the way we're going to gather this is by using numbers to call out or see where the actual information can be referenced. So we're going to do result two, result two. And then we're going to say full name is going to be saved that position one because the way we check this is we start from counting on zero. So on position zero is ID. On position one is full name. Position two is age. So position one is the result. I mean full name. We're just going to refresh this and syntax error result two on line 65. Okay. Let's fix that quickly. Just put a dot in the middle. And as you guys see right here, it says full name dsa dsa dsa which is the full name we obviously saved. We can obviously just if you want to make it easier and more formatible just put it in here. It shouldn't matter anyway. And then we say up here we're just going to do echo count details. Save the count details. And then we say that. And then if we copy and paste the same thing over and over again, we should be able to gather the rest of the results as well. So after full name is the age. So we're going to type in age, then we're going to type in weight here. We don't need the username. The username for was for our reference purposes. So yeah, we're just going to update this to two and three because that's the position in the array for the data that we're looking for. If we refresh, it says all the details that we need. But the only problem here is it's not formatted. So we just do paragraph, paragraph, paragraph, paragraph. That should do that for the formatting. And as you guys can see right here, if we clear this echo result thing, the one should disappear as well. It says saved account details, full name, dsa, whatever, age 21 and wage 12, same as the database. So that's how you would normally create an account. Obviously we've learned that and that's how you would take further information from the user using like a mini form that we've used here. We could obviously design this better, but already this tutorial has been long enough. So I didn't want to make it more boring for you guys, which is why I kept it a bit more shorter by not designing it. And if we click on finish, we also have validation which prevents the user from creating double entries into the database. And that's about it for today's tutorial guys. Hope I was able to help you. I know this is really basic for you guys that already know about PHP, but this was really aimed for beginners and I tried to keep it as easy as I could. Hopefully I didn't confuse you guys. Obviously you can leave me some feedback about this tutorial in the comments. And please let me know if you like a Python tutorial in the next video or should I carry on with PHP. And I'll see you in the next one. And don't forget to subscribe. Bye.