How to Upload Profile Images to Users Using PHP

today we're going to learn how to upload profile them just to users inside a website and this is going to be based off directly at the previous episode I did was show you guys have to upload images and files directly to a website so if you guys haven't seen the previous episode I recommend you guys go back but first and then return to this episode here because all the co2 gas in front of me here is directly the same as what we did in the previous episode and we will continue to build on the system here we created previously now another thing i should mention is that we also need to be able to create a login system because it makes sense that in order to make a profile image upload system we need to have a login system so if you guys don't know how to make a locking system i also recommend gasps go back to episode 39 well show you guys how to create a locking system so having said this let's actually go ahead and take a look at what we're going to be building this episode here so what you guys in front of here is going to be the prototype we're gonna be building today and yes I know doesn't where pretty I didn't focus on styling today so if you guys want to make it pretty just need to add some CSS to it now what we're going to be doing here and I'm just going to take this one by one so you guys understand what is going on inside my browser here is first of all at the top of the page we're going to go ahead and list out all the users we have inside the database now right now as you guys can see I have no users because I didn't sign up any users down here so what we're going to do underneath here once we get all the users is we're going to get a message that says it was locked in a knot because I do actually have a login and logout button down here now I didn't create a traditional login system we have a username input field and a password field and then click lock in because we're just creating this as a test today but it's going to work exactly the same way for uploading profile images had been a regular locking system ok i just had to create a button instead of a input field we also have a lockout buttons we can lock out our admin again that's basically what we have for locking system then up here i have a signup form we can sign up and you use it inside our website so what I'm going to do here is I'm just going to demonstrate what it is we're going to be doing and how to upload system is going to work so I'm going to go and sign up myself Daniel Nelson i'm going to call myself fat man cuz we need to be able to lock in as admin down there i'm just going to create a one-two-three password and then after click Sign Up you guys can see we get admin now what you guys will notice is there right now as a default once i click Sign Up i haven't uploaded any kind of profile image yet so as you guys can see I get this default profile image and this is actually something i upload inside my uploads folder inside my root folder as you guys can see you get this profile default the JPEG image now once had to actually click and lock in you guys can see we now get a profile image upload system that replaces my signup form because I'm locked in we should be able to sign up anymore and instead we can upload a profile image now this profile image is going to go in and replace the default image we have up here so go in and say choose file and select myself click upload you guys can see a now teens my profile image so this is a pretty cool way to change it now if I wanted to change it to another profile image i would just go and choose another file another image like this guy down here upload him and as you guys can see we now get a new profile image so this is basically what we're going to do today so hope you guys find is useful because in a second i'm just going to delete everything on the screen here and then we're going to build everything from scratch ok so now when hadn't deleted everything inside the prototype except for what we did in the previous episode so as you guys can see this is all identical to what we did previously in the last episode ok so the first thing we need to do to create this upload system is that we need to create the database we're going to use in order to upload these images so i'm going to go into my database or decent I PHP myadmin and as you guys can see already created a database called image upload so if you guys don't have a database yet or if you already have one running for another website just going to use that database and create one first so inside my image upload database we're going to go and create two tables i'm going to go into the SQL tab up in the top here you can write SQL code and I'm going to go and create two tables the first one is going to be to use a table we're going to say create user or create table not user of course and then we're gonna call this one user we're going to go to insert some values or some values for the columns are going to insert into the user table so we're going to say parentheses and then semicolon and inside of here we're going to say that the first column is going to be named ID the ID is going to be a data type set as integer we're going to set it to maximum of eleven characters we're going to set to not know and then we're going to go and set this one as our primary key we also need to set it to auto increment so it automatically updates to a new number higher every time we add a new user like so and then comma and then on the next line we're going to go and say we have a first name we're going to say first we're going to create a bar chart data type going to set it to 256 not now and again this is all stuff you guys know how to do by so we're just going to move a little bit faster here so last name down to 56 not now and then we're going to create a username i'm just going to call what we have up here because it's gonna be completely identical and then the last one is going to be the password is a password is can be much as well 256 and not not and no come at the end here so after we created the table for a user can actually go ahead and run the code after Randy code need to create a second table because once we create this image upload system we need to be able to tell if we already uploaded an image of we didn't because if you haven't uploaded a profile image we need to get the default image that i showed you guys inside my uploads folder so what we're going to do here is i'm going to create a new table and this table is going to tell us the status if we already uploaded a profile image or not we're going to say create table profile image again we're going to insert column values the first one is going to be an ID completely the same as we did for the users want to say integer 11 not know primary key and auto increment it like so now the second column is going to be the ID of the user inside the user table want me to actually need to link the profile image we haven't here to the users so we need to know which user has which status of this profile limits so we say use ID which is going to be the next name for next column we're going to say integer because the idea of the users inside the user table is an integer as well so why not just make an integer 11 characters and not not then we need one more piece of data because now we told it which user has this image status so now we need to actually set the status as if we uploaded or did not upload the image yet so going to say status like so integer 11 characters and not not so that's all we need for a profile image table we have in here we just need to know which use the images link to and did he already or did he not upload a profile image so we're going to go ahead and say go so now we created the database we're going to use for this entire episode so that's all we need to create in here so going inside our code the first I'm going to do inside index2 PHP file is we're going to go ahead and set a session at the very top of our page because I want to be locked in we need to have a session running inside the entire page i'm just going to go ahead and create a session up the very top here we need to a mobile PHP tags like so and inside the PHP tags to create a session underscore start so now we have a system started on the entire front page which we need to have now the next thing we're going to do is we're going to go ahead and start a connection to a database or these Creative Connections we have it for the database im global new file and I'm going to go ahead and save this one as DB h dot PHP inside my root folder now the code we're going to run in here is going to be the opening PHP tags first of all we need that and we're going to create a variable called on which is equal to the parameters we need in order to tell it which database for connecting to go into say my sqli underscore connects parentheses and inside of you will need for different parameters first of all we need to tell which server will actually choosing for the database which in this case is localhost because it's not online comment the next one is going to be the username which in my case is root for my exempt and then the password is going to be empty because i'm using xampp again if using another program for your localhost then you need to go and check in which username and password you have for it the fourth parameter is going to be the database name in my case I decided to call mine image upload if you have another name for our database need to change this to whatever you have for yourself so we're just going to go and create this because we're not going to do a bunch of error messages were just going to create the very basics in order to get this image upload system running because this part here is also if you guys go to learn when we created a login system so we're not going to go too much into detail here so once I have this we can actually go ahead and go back to index page and we can link this dbh document to our front page so their top here right underneath the session start going to go and say include underscore once single quotes dbh dot PHP so now included this document in here so now we do actually get a connection to the database so the next thing we need to create is our login and logout forms of course we could do this and then kind of order we wanted to but i'm just going to go and create the lock-in lockout form first because why not so what we're going to do is we're going to go ahead and go underneath the former created in the previous episode we did actually upload images i'm going to go and create a forum down here now this form is going to be our login form i'm just gonna go ahead and set a action which is equal to walk in dot PHP i'm going to set a method as post and then I'm going to go and give it a button now we're not going to give it an input because remember i'm not trying to create a an input field for a username and password i just want to button that i can click and get locked in as the first user created inside the database which in this case is the admin I'm just gonna go and create a button i'm going to set the button type as submits i'm going to go and give it a name which is equal to submits lock in like so now inside the button we can go and say luck in two so we know what it does and i'm going to go and create a paragraph right on top of the form so we can tell ourselves what does form does i'm just going to go and create paragraph tags and I'm going to go and say lock in as user so know what it does now we're going to go and create a second form just going to copy everything we have up here because it's going to be pretty identical to it and this one is going to say the lock out as user like so now we're going to go and change the action to lock out the PHP and we're going to go and change the title inside the button to lock out like so was going to change the name of the button so it doesn't say so good luck in to say submit lockout and that's basically what we need to do for the forms we have in here so now we need to create documents that allow for us to lock in and allow us to lock out argo over- documents i'm going to go ahead and save it as lock-in dot PHP inside the root folder and inside this five we're going to go and open up the PSP tags now we're gonna go and create a session that has started because we need to have that in order to lock in a person when he clicks the button need to have a session running underneath here we're going to go and create if statements and inside the conditioned we're going to go ahead and check if the button has been clicked so want to say is set parentheses and then we're going to check for post method called submit lock-in it was a dollar sign underscore post brackets single quotes then we're going to say submits lock in with a big out at these my case the road as a big girl now inside the if statement we're going to go ahead and lock in the person as the person inside the database that has a session ID or these night d as one so going to say we have a session variable which is a super global by the way you guys noticed by now if you know how to create a login system and we're going to go ahead and call this one ID i'm going to set it equal to 1 because we just want the first ID from the database and again we're not actually getting anything from the database I'm just saying I want to be locked in as the first user inside the database that has the ideas 1 i'm not doing any kind of special thing in here so underneath here the last thing we need to add is ahead of function so we can actually be taken back to the front page once we did actually lock in i'm going to say double quotes location with a big girl and then we're going to go and set it to index dot PHP and that's all we need to have inside the log into PHP file now the next thing we need to add is we're going to go and add a lockout file so going to save a new file of lockout that ESP and then we need to do kind of the same thing in here when he just first of all start out the PHP tags and then we need to set a session start because in order to destroy a session when you have it started first then we're going to set a session on the score unset which unset all the variables we have inside our session variables and then we're going to destroy afterwards with a session underscore destroy like so so now we just locked out person out if it does actually click the logout button now we also need to be taken back to the front page we're going to create a header function here as well called the exact same thing lockout or location that lockout call on index dot PHP so now we just created a login and logout button that actually works and now what we're going to do is we're going to go ahead and tell the website what we want to see if I locked in and what we want to see when locked out so we're going to go back into the index.php file the very top of the body we're going to go ahead and open up PHP code with the PSP text and then inside the PHP tags are going to create an if statement and this if statement is going to check if we're locked in so what we're going to do is we're going to check for a session ID that set as ID so going to get dollars on the score actually no we're going to say is set parentheses and then dollar sign underscore session which again is to superglobal that has a name as ID so now we're just checking if we are locked in then do whatever is inside the if statement so what we want to do inside the if statement is we want to create another if statement because we want to check if we logged in as admin or at least the first person inside the database we're going to say is set parentheses and then we're going to say if the session ID we have up here is equal to one then write something inside this if statement we're gonna say echo you are locked in as user number 1 or something we could also called that men if you wanted to but right now basically locking yourself in as user number one from the database so we're just going to say user number 1 now we also want to do is you want to go ahead and show if we are locked in the format created in the previous episode that allows for us to upload images because we don't want to see the former we can upload profile images if we're not locked in we should only be able to upload images if we're locked in i'm going to go ahead and copy this form down here delete it then I'm going to go and go inside the first if statement after the second one and then i'm going to go ahead and echo a string which is going to be this for me just copy down there now of course we do need to change these double quotes to single quotes because we have single quotes around it just going to do that really quick like so like so like so and change them so now we basically have our image upload form inside the if statement tix if we're locked in because now if I'm not like then we can actually see the form so what we can do now is we can actually go and test is really quickly just to see what's going on if it turns out the website you guys can see oh we do actually get an error message let's actually go ahead and fix that we don't set and is set for if we're checking if the session ID is equal to 1 we just need to check if this is an idea is equal to one so if you caught that mistake great job so now if you go back to the website refresh you guys can see now get this right now it says you are locked in as user one so we're going to say lockout we don't get a message if i click login we get a message so this is basically working like we wanted to so what we can do now is we can go ahead and so on message if we're locked out because right now as you guys can see we don't see anything if i go inside my code right after the if statement which says if we're locked in and do this down here we can go and create the else statement now inside this else statement we're going to echo you are not locked in just as you can see we're not locked in as you guys can see if i want to go back it now says you are not locked in then if you lock in it doesn't say it anymore so what we need to add underneath here is we're going to go ahead and add a signup form because we're not locked in we want to be able to sign up a new user so what we're going to go ahead and do is we're going to go down to the next line we're going to start creating the HTML form that last ones to sign up a new person you want to echo a string and then inside the string we're going to create the form tags like so that inside the form tags are going to go and create the inputs we need in order to sign of a person so we need to say input which is going to have a type which is equal to text we need to set a name which is equal to first because now we're going to go into the database make sure that all the input fill out what we have inside to use a table so we're going to the structure of my user you guys can see we have a first name we have a last name a username and a password so we need to fill out all those four fields of course the first one which is die d is not going to get filled out because it does it automatically going to go back inside out code and inside the input going to go ahead and put a placeholder you can actually see what is written inside this input inside the browser going to say first name then we're going to close the input and then we're just going to go ahead and copy it down three more times like so then we're going to go and change the second one to last inside the name going to change to placeholder to last name then the third one we're going to go and change the name to use the name for these uid which in my mind central username inside the placeholder we're going to say username in the fourth one we're going to change the type to password going to change the name to PWD i'm going to change the placeholder to password XO then we're going to create a button like so and inside the button tag we're going to go and set a type which is equal to submit we're going to go ahead and set a name which is equal to submit sign up and this is basically all we need to do for the inputs now inside the form tag at the very top here we also need to set them action and a method so going to say action which is equal to login dot PHP then the method is going to be equal to a post method so now we just created everything needed for luck inform the signup form not to login form so we go back to the website you guys consider once we lock out we get a signup form of course we forgot to put something inside the button lets do that really quickly so inside our button down here inside the signup form we're going to say sign up now to look correctly there we go so now we have that we need to create the code in order to sign up a person inside the database in order to do that we need to see what is going on inside the browser so before we start setting up people we should probably create the thing that tells us how to use it looks like inside a browser so you guys remember to tell my prototype you could actually see if we had to use inside the database or not and if we had a user it showed us what the username was what the name of the person was and what the profile they must looks like you need to create that first and then we can start signing people up so at the very top of our page here inside the body tag actually no inside the PHP tag up here we're going to go ahead and start selecting users from the database because we need to see if there is any kind of users from the database and if there is we want to show them inside the top of our website if there isn't any users they want to show a message that says there are no users so the first thing we're going to do is we're going to go ahead and create a select statement to need to write SQL code so we want to save have a very so called SQL which is equal to double quotes select all from user that's crazy what we need their next line we're going to go ahead and run this query going to save dollars on result which is equal to my SQL eye on the score Cory parentheses semicolon and then inside the parentheses we're going to say we have a database connection inside our dbh the PSD file which is called the sign con which is going to be the first parameter because we need to connect to the database and then for the second parameter need to run the SQL code up here to get all the results from this SQL string we which is queried on the next line we're going to start spitting out the results so first of all we're going to go to check if we actually got any results from the database because we don't have any users inside the database yet we're going to get an error message if you start spitting out stuff so first of all going to say if we had any kind of database results by writing my SQL i underscore num underscore rose parentheses from the quarry ran called dollars on result that is greater than 0 so we had any more resource 20 running this corey up here then we want to run the code we have in here and in here we want to say okay if we had any results then while we have results we want to spit them out so i'm going to create a while loop there we go so inside the while loop we're going to see a dollar sign rope which is equal to my SQL i underscore fetch underscore that suck parentheses from the quarry ran inside the Select statement Excel so if you got any resource and spit out each row result inside a while loop based on this corey up here so now we did this normally we would start spitting out the stuff we want to see from the user in not the database of want to show a dip box with the user image and the user you know the username and the the first name and last name i could go ahead and start writing it inside this while loop but we can't do that yet because first of all we need to check if we have uploaded any kind of profile images to this user yet because based on that we're going to have to run another select statement that goes and checks if we already uploaded a profile limits so in order to explain it to you guys properly before we start writing anything new this going to go back inside the database just show you guys what's going on here now inside my user table the first years i'm going to sign up is going to have an ID which is equal to one now because that users going to have an ID we also need to say that once we sign this person up he needs to have a row inside a profile image table which at the moment looks like this so inside the profile image stable need to tell it what to use ideas of the user and what the status is did he already uploaded did he not upload a profile image so based on the status we need to say do we want to show the default image inside the folder that you want to show a new image that he uploaded himself so in order to check this and need to check the user ID in here need to create another select statements or at least we need to first of all get to use ID of the person who is inside to use a table so we're going to go ahead and say dolla sign ID which is equal to cosine row single quotes ID which now gets the ID of the user just selected from the database now because we have this we now can go in and check the database inside the other table we have if the status of this user says that he already uploaded a profile image so we're going to create another select statement we're going to get dollar sign SQL which is equal to select statement that's actually going to change this text we have SQL image which is equal to a select statements we select all from profile image inside-out table where the user ID column that we have inside to use it inside the profile image table is equal to the idea we have up here we just got from the user so now we're checking if we actually have a profile image uploaded from this user now the next thing we're going to do is we're going to go and run this query inside the database so we can just go and copy what we have up here we actually run the previous query and then just change to name of it down here so we don't have SQL we have SQL image and then contains the result name over here so we say you have results image and then we go ahead and go in and check what the status is of this user inside the the image table we created so just to recap for you guys to basic thing that's going on here is that we're going into the database checking if we have uses inside the database if we have users then start looping them out one after another but each time loops out one user is it also going to check if that user has an image that he uploaded inside the root folder of our website now the image what the status is going to show inside a profile image table and based on that we want to show the image we don't want to show the image that you uploaded or not so after we did this we're going to go and run another while loop and inside of here is where we're going to start looping out the data we want to show inside the browser because now we have data from both database tables and we can start spitting out whatever we have from them so inside the parameter this while loop we're going to go and say if alessandro image equals my SQL eye on the score which underscore stock parentheses then we're going to get dollars a result image from up here we're going to insert inside the parentheses so running this query up here and now we can start spitting out information want to show inside the website so now we create the while loop we can actually start spitting out the stuff we want to see inside the browser for example a tip box with the images inside of it and they use name and it's the first and last name of the user you can start spitting that out so what we're going to do here is I'm first of all going to a cloud a strength is going to be a dip box i'm also going to go to close to did box in a second echo underneath here because we need to put some stuff in between like so and then the next thing we're going to do is we're going to go and check if the status of the image says it's uploaded or not uploaded already going to create if statements when we go into the second career and which is called alessandro image brackets and we're going to check if the status inside this column says that the image has been uploaded if it has not been uploaded yet you want to say if it's equal to 0 then we already uploaded an image but if it's not zero they want to create an else statement down here that says we haven't uploaded and image yet so we need to echo out the default image inserted inside my my root folder inside the upload folder we're going to go ahead and dig in a path going to create an image has a source equal to single quotes uploads /a profile default dot jpg the natural single quote we're going to go ahead and close off the image tag so now we're basically showing the default image to have inside the root folder if we don't have any kind of changes made to the profile image yet now inside the other if statement up here we're going to copy this echo going to insert it and instead of writing profile default you want to write profile and then delete the default we're going to start up ESP code again by riding double quotes and then to punctuation and then we want to show the user ID from the user inside of here because now the name of the MS is going to be profile one because the gun locked in his right now has an idea is one inside the database so right now the images can be called profile one so what we need to make sure we do now is that once we do actually upload a new profile limits we need to change the name to something else than a unique ID who created in a previous episode as you guys can see down here will create the new file name we made unique ID which we now need to change to whatever we have inside here instead okay i need to do that in just a few minutes so one last thing we need to do is we need to go ahead and say well if we had no users inside the database yet then we need to have an else statement that says there are no users inside the database so there are no user signed up yet we're going to echo out an else statement that says there are no users yet now we need to finish off what we have inside the Dybbuk box because right now we're just showing the image but i also want to show the user name and first name and last name of the user these just use name doesn't really matter so right underneath the else statement we're going to go ahead and say you have an echo that echoes out the username of the person inside the database to right now I want to go up and grab the query from the last result we got up here which is does on rope and say we have a column called username so now we're going out to user name and the image of the person inside the database so now we created this we're basically done inside the index page except for one more thing you need to do at the end but now we need to do is we need to make sure that when we sign up new person using the signup form we have down here that we insert data inside the user table and inside the profile image table inside the database once we've done that we're basically done creating this image upload system well we also need to change the public php5 we have inside from the previous episode but that's really easy code to do so we're almost done so what we're going to do now is we're going to create a new file we're going to save it as a sign up dot PHP and inside of here the first thing we're going to do is going to open up the PSP tax and then after click the sign up button inside our index page need to grab the data to be passed on from the index page right now you guys can see if I go down to the signup form we have a first name last name a username and a password so inside the sign of the PHP file going to say we have a variable called first which is equal to a superglobal called post that has a name as first then we're just going to go and copy this paste it down three more times and then we're just going to go and change the names inside these variables and inside superglobal so the second one was called last in the third one we called it uid and the fourth one called the PWD for password so now we have this we can start inserting the data inside to use a table so what we're going to do is we want to create a variable called SQL which is equal to double quotes insert into the user table parentheses space values space parentheses semicolon at the end and then we need to insert the column names and the values we have from up here so in the first parent disease we're going to say we have first comment last comment username comment password then I'm just going to move this down to the next line just so we can see this better and inside parentheses here i'm going to say single quotes then the variable first we have up here like so kama single quotes herbal last comment single quotes variable uid comma single quotes and then dolla sign PWD so now we're just inserting data inside the user table for these we have the string that we need to query in order to insert it into the user table underneath here going to a dollar sign result gonna set it equal to my sqli on the score Cory parentheses then we need to get the database connection which we haven't gotten yet so need to go to top the page here include underscore once single quotes dph dot PHP semicolon because now I can go and get the database connection which is dollar sign con comment and then we want to run the query which is up here called those on SQL and once we've done this we signed up to user now one small detail just noticed is that we don't actually need to have the dollars on results equal to down here so just going to remove that and then right underneath where we have the insert statement we now need to go into the database select the user just inserted into the database so we can use this information to create a new row inside the profile image table inside out database so on the next line here we're just going to copy everything we have right here and instead of an insert statement going to create a select statement so going to say select all from user where uid or not you would either username is equal to u rd from up here and first is equal to the first name we have up here now you might be asking why am i doing two different parameters down here that simply because we want to eliminate as many arrows as possible if a user for some reason has signed up his username as a sack same thing as another user then we would end up going in an overriding that first user so want to make sure the username and the first name is the same just to make sure there's less errors so after we have this we can now go down to the query down here and we can go ahead and say that we have a variable called results that is equal to the quarry which is ran in here after the query then running if statement and inside the condition of this if statement want to check if we had any results from the Select statement here so going to say if my sqli on the score numb underscore rose parentheses from the dollars on results here greater than zero so we're more than one result then it needs to run this code down here else want to give an error message that says echo you have an error or something inside the if statement we now need to get the data from this user we just inserted into the database so i'm going to go ahead and say we have a while loop parentheses curly brackets and inside the while loop condition we're going to see a dollar sign rope is equal to my sqli underscore pitch on just go as suck parentheses and then we're going to say double somersault inside the parentheses so now basically getting all the data from the user just inserted into the database inside the while loop we want to get one piece of information from this user we need to get his ID inside his column so going to go and say we have dollar sign user ID which is equal to alessandro brackets and inside the brackets want to say we want to get the ID of this user here so now we have the ID we can actually go ahead and insert a new row inside a profile image column so what I'm going to do here so I'm going to go and say we have a new insert statement i'm just going to copy what we have up here peso need here move everything out so it looks nice like so and then we're going to change it from insert into user to insert into profile image then we're going to change it inside the parameters because we don't have to i'm going to change the from first to user ID and then from last status then inside the values also going to delete the last two because we only have two different parameters want to change the from dulles on first to use ID because we want to insert the user ID of the user inside the user ID inside the profile its column and then inside the second parameter we're just gonna go to delete what we have here and right one now the reason we're riding one is because right now set the index page once we loop out the user inside our website checking if he has a status inside his profile image set to 0 or 1 if it's zero then we'll bring out the profile image he uploaded if it's one then it will basically saying that he doesn't have a profile image yet so right now because it's just signed up he doesn't have a profile limit yet so now we're going to go and save this and the last thing we need to do is we need to take us back to the front page you're going to say header at least they had a function location col1 index dot PHP so now we basically have everything we need in order to test is out because it should be working now so if we go back inside our website you can actually go ahead and refresh everything right now it says there are no users yet you're not locked in because when I locked in we didn't create any users yet if i want to go in and try to sign myself up with daniel wilson admin why not 123 sign up you guys can see we now get a profile image my username with now stores we have a user inside the database of course it doesn't look exactly the same as what i showed you guys my prototype because we have an X because we haven't actually style anything yet but as you guys can see we now have the profile image and admin so now we have the profile limits of what i'm going to do really quick is I'm going to go and style this very quickly i'm going to show you guys to code you guys can copy yet but I'm just gonna go and paste in some code i created from a prototype so the first thing I'm going to do to make it look nice is I'm going to go into my index page I'm going to go into my div that have inside my while loop in here and i'm going to go ahead and give it a class i'm going to give it a class named as user gas container then I'm going to go and say that the user name down here is going to be inside two paragraphs or inside one paragraph like so and like so and then i'm going to go into my style sheet which you haven't created yet just going to create one really quick going to save it as style.css XO and then I'm just going to place and all the code i have my styling again if you guys wanna see it is i'm going to leave a link in description for you guys we can download this style see link so you can just paste and if you want to so now i'm just going to go into my index 2.php file I'm going to go ahead and link to the stylesheet up at the very top style dot CSS and now i'm going to go into the website we've rested and as you guys can see we now have a bit of styling it doesn't completely oakley so what I'm going to do now I'm going to go and lock in my user by clicking lock in as user once unlocked in it says you're logged in as user number 1 and now connect to start uploading profile images to my profile here but we need to make a small change to the document created in the previous episode which is the one called upload the PSP because we don't want the name to be some kind of unique number and we need to make sure that once we upload a new image we also make a small change to the database so the tower this document here we're going to go to start a session XO and once we start a session I'm going to go ahead and go underneath here connect to my database file and include underscore once dbh dot PHP after including the database file we now need to get decision ID of the user is just locked in because no to change the profile limits we now need to tell the database who we are as a user so which kind of use name or use ID you currently have so underneath include i'm going to say we have a variable called ID which is equal to the current session ID like so so now we have everything we need in order to change the name of the file we're going to upload i'm going to go back down to where we just create a new file name called dollars on file name new and i'm going to go ahead and delete unique ID we have down here first of all we're going to go and include a new string going to double quotes i'm going to say profile then after double quote we're going to say punctuation and then we want to reference to the current session ID was a dollar sign ID so now the name of the file is going to be profile than a name of my current session ID punctuation and then the file extension so now we have this all we need to do now is go into the profile image database table and update information we have in there because right now the status is set to one which means that we haven't uploaded profile image yet but we want to change 20 to tell it that we just uploaded and image we now have a current profile image inside our root folder so right before we go into the header location of the head of function down here because we need to do this before we go back to frontpage we're going to go ahead and write an SQL statement going to save dollars on SQL double quotes and I'm gonna say update profile limits and we're going to go and set the status column equal to 0 where the user ID is equal to current session ID so dollar sign ID and our last thing you need to do is we just need to run the query and after that we just need to do one more thing which is very short and then we're done i'm going to say dollars on results equal to my SQL eye on the score quarry parentheses semicolon and inside here we're going to get the database connection for con and then we want to get dolla sign SQL so now that we did this we can actually go and test is because now should be working so we're going to the website be fresh choose some kind of profile image and I select maybe myself in here upload once we get a error message upload the pline 27 it's actually going to check that out ah i forgot to add a semicolon to end here there we go now we can go in and check that is working the second refresh again choose a file and upload and as you guys can see my images changed because now if you go into the database going to the profile image it now says my status is equal to zero meaning that i now have uploaded profile image even though we set as one when we created the user if i were to go in and create a new user just three guys going to call this one Jane though going to call her something else 123 and her up now you guys can see that she also have the default image if you're going to the profile image database just to show you guys her image that is right now says that she has a status as one being that she doesn't have a profile minutes if i were to lock in as Jane and change the image it will get tends to 0 which is what adjusted with my profile so this is basically how we can do this now one last thing i want to mention is that if i were to go in and change my profile image again for the lock-in choose another image right now you guys can see didn't change for some reason even though i just upload a new image and it's not an error caused by the image file name or anything like that but it's actually because some browsers can remember how images look like so forward to refresh is enough times you guys can see now changed so we want to make some kind of change so it doesn't happen so it needs to update the profile minutes right away after change the image now I want to do that we're going to go back inside index the PSP and inside index 2.php we're going to go down to where we have the name of our image right now says we have profile variable ID at the APEC right after a JPEG we want to add a random number or some kind in order for two always update the name of the image because it just keep updating to image without changing the name then the browser is going to think it's the same image as last time right before between two image so want to update it right away we need to update the name of the image when browser loads dammit so after jpg we're going to say ? and then after the single quote going to say double quotes because we want to change the to PHP code right now punctuation marks and then we're going to go and create a function called Mt on the score random which is going to give us a random number between a certain amount of numbers we're going to say parentheses now because we're not setting any kind of parameters and he's just going to give us some kind of random number so this is basically all we have to do for this episode i hope you guys find it useful even though is quite long but this is basically how to his profile images but he's one of the ways you can change profile images because there's quite a few ways you can do this so guys enjoyed and I'll see you guys next time