PHP-and-MySQL/C4/User-Registration-Part-3/English-timed
From Script | Spoken-Tutorial
Time | Narration |
---|---|
0.00 | Welcome to the 3rd part of the User Registration tutorial. In this part we are going to check for existence of all that was discussed in the last part. |
0.07 | Let us have a quick recap of what was done in the last part. |
0:09 | We have striped the tags off our "fullname" and "username". |
0:12 | We have stripped and encrypted our "password". |
0:17 | Remember this sequence for the functions, so that we are not striping off our encrypted value. |
0:23 | Here we are going to start our registration process. I'll be checking the existence of all these. |
0:33 | Just before I do that I am going to set the "date". Now, this is using the date function. |
0:38 | Inside we have "Y" for the year "m" for the month and "d" for the date. |
0:45 | It's the capital "Y" for a 4-digit year. If we use a small "y", we would have a 2-digit year. |
0:59 | So, in my database, at the moment. I have my year first, then my month and my day and these are separated by hyphens. |
1:08 | You can see this when we enter our database here and say insert a value into "users". |
1:13 | We can see that the "date" is in a specific format, if we use this kind of function here. |
1:19 | When I click today, you can see here that we have got the year in a 4-digit format and our month here and our day here, separated by hyphens. |
1:29 | Its adjusted into that structure inside my database. |
1:33 | Okay, so "if submit", then we need to check for existence. I will add a comment here "check for existence". |
1:46 | Now, this is really easy. All we want to do is we have to say is "if" statement and a block a code after that. |
1:55 | The condition will be "if fullname, username, password and repeat password exist".... we have the evidence here.... we will say "if username" followed by "and", so double ampersand symbol. |
2:10 | Then we will say "password" and then we'll say.... |
2:14 | Oh! I forgot the "fullname" here, so I'll add it here. |
2:18 | Separated these with a double ampersand sign. |
2:21 | The last one is "repeat password" so type that. |
2:26 | We are going to require all of these. |
2.31 | Else, we will say - echo "Please fill in" and in bold, "all fields". |
2:42 | We will put a paragraph break after that. |
2:45 | Also let me put a paragraph break before the form so that we don't need to add it to every error message we give. |
2:57 | So that's it. Let's just try it. |
3:00 | I will go back to my "register" page. We got it here. Lets click in register. |
3:05 | "Please fill in all fields". |
3:07 | Lets type a couple of fields here. |
3:10 | Lets choose one of our passwords. We will not repeat our password. |
3:15 | Register. Oh! repeat password..... repeat password. |
3.32 | The reason this is not working at the moment is, an "md5" value of nothing is equal to an "md5" string of text. An encrypted string of text. |
3:44 | So, I realise what we need to do is, take out the "md5" function here. |
3.51 | Make sure you remove the end brackets. I will come down here and check for all of our data. |
3:59 | So, let me go back and try this again. |
4:01 | Remember it didn't work before when we didn't chose a "repeat password". |
4:05 | So if I didn't chose a password or a repeat password we get our error. |
4:10 | If I again choose a value except the repeat password, we still get this error. |
4:16 | That's the problem. What we should say is - if everything exists then we can convert our password and repeat password. |
4:25 | So I will just say "password" is equal to "md5" of password". |
4:30 | This will encrypt our original variable value and store a new password code in the same variable. |
4:40 | We also need to say "repeat password" equals "md5" and "repeat password". |
4:52 | Here comment this as "encrypt password". We have encrypted our password. |
4:58 | Now we will go ahead and add all our data into our data base. |
5:07 | I am going to do this. Because we have got our data going to our registration, we are going to set a maximum limit for each data that is input. |
5:19 | Now we say 25 characters for our fullname, username, password and repeat password. So the maximum value is 25. |
5.32 | So I will say- if the string length of username is bigger or greater than 25.... or.... string length of the fullname is greater that 25 |
6:00 | Let us look at these individually and say if the length of your username or fullname is too long. |
6:09 | Let me put this correctly. |
6:12 | If each of these values is greater than 25 or bigger than 25. |
6:15 | We are going to echo out these values saying "username" or...... no.... |
6:25 | Let me say "Max limit for username or fullname are 25 characters". |
6:36 | Otherwise I will proceed to check my password length. |
6:40 | Now I have decided to do this - "check password length" because I want a specific check for this. |
6:48 | Let me say "if string length of my password is greater than 25.... or.... string length..... |
7:08 | No... um... lets get rid of this, get rid of "else". |
7:15 | The first check I want to do is to see if my passwords match. |
7:21 | Let me say "if password equals equals to repeat password" then continue the big block of code. |
7:31 | Otherwise echo out to the user "Your passwords do not match". Okay? |
7:41 | So, you can type here and we can keep checking our character length. |
7:44 | Now to check the character length of "username" and "fullname". So, "check char length of username and fullname". |
7:56 | And that is going to be what we said before, "if username is greater than 25" |
8:02 | Rather if the string length used in this function is greater than 25... |
8.08 | Or the string length of fullname is greater that 25, then we echo "Length of username or fullname is too long!". |
8:24 | So, just to keep it simple and then otherwise we will say "check password length". |
8:36 | Here I am going to specify or say "if"... now remember our passwords match... |
8:42 | So we only need to check this on one of the password variables. |
8:46 | Here I will say - if the string length of the password is greater than 25 or string length of our password is lesser than 6 characters.... |
9.00 | ...then we will echo out an error saying "Password must be between 6 and 25 characters". This will work for sure. |
9:16 | We will continue this discussion in the next tutorial. |
9:19 | Before that let me just conclude this with an "else" statement. |
9:25 | So, otherwise we will say "register the user". Our code to register the user will go here. |
9:35 | In the next tutorial we'll test this out and will learn how to register the user and we will put our code here in that tutorial. |
9:42 | This is basically for checking a minimum or maximum limit on our password and this block of code here is will be our magical "register the user" piece of code. |
9:52 | So join me in the next part. Bye-bye. This is ____________ dubbing for the Spoken Tutorial project. |