PHP-and-MySQL/C4/User-Registration-Part-3/English-timed

From Script | Spoken-Tutorial
Revision as of 11:25, 28 April 2017 by PoojaMoolya (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Time Narration
00:00 Welcome to the 3rd part of the User Registration tutorial.
00:04 In this part, we are going to check for existence of all that was discussed in the last part.
00:10 Let us have a quick recap of what was done in the last part.
00:14 We have striped the tags off our "fullname" and "username".
00:19 We have stripped and encrypted our "password".
00:23 Remember this sequence for the functions so that we are not striping off our encrypted value.
00:30 Here, we are going to start our registration process.
00:34 I'll be checking the existence of all these.
00:38 Just before I do that, I am going to set the "$date".
00:43 Now, this is using the date() function.
00:47 Inside, we have "Y" for the year, "m" for the month and "d" for the date.
00:55 It's the capital "Y" for 4-digit year. If we use a small "y", it would be a 2-digit year.
01:02 So, in my database, at the moment, I have my year first, then my month and my day and these are separated by hyphens.
01:15 You can see this when we enter our database here and insert a value into "users".
01:22 We can see that the "date" is in a specific format, if we use this kind of function here.
01:29 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.
01:40 It's adjusted into that structure in my database.
01:45 Okay, so if '$submit' then we need to check for existence.
01:51 I will add a comment here "check for existence".
01:55 Now, this is really easy.
01:58 All we want to do is, we have to say "if" statement and a block of code after that.
02:05 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.
02:24 Then we will say "$password" and then we'll say....
02:28 Oh! I forgot the "$fullname" here, so I'll add it there.
02:33 Separate these with a double ampersand sign.
02:38 The last one is "$repeat password"; so type that.
02:42 We are going to require all of these.
02:46 Else, we will say - echo "Please fill in" and in bold, "all", "fields!".
02:57 We will put a paragraph break after that.
03:01 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.
03:10 So, that's it. Let's just try it.
03:13 I will go back to my "Register" page.
03:17 We got it here. Let's click in register.
03:20 "Please fill in all fields!".
03:22 Let's type a couple of fields here.
03:25 Let's choose one of our passwords.
03:27 We will not repeat our password.
03:30 Register. Oh! repeat password....
03:42 '$repeat password'.
03:45 The reason this is not working at the moment is, an "md5" value of nothing is equal to an "md5" string of text.
03:56 An encrypted string of text.
04:00 So, I realize what we need to do is, take out the "md5" function here.
04:06 Make sure you remove the end brackets. I will come down here and check for all of our data.
04:14 So, let me go back and try this again.
04:17 Remember it didn't work before when we didn't chose a "Repeat password".
04:23 So, if I didn't chose a repeat or a password we get our error.
04:30 If I again choose a value except the "Repeat password", we still get this error.
04:37 That's the problem. What we should say is - if everything exists then we can convert our password and repeat password.
04:46 So I will just say "$password" is equal to "md5" of "$password".
04:53 This will encrypt our original variable value and store a new password code in the same variable.
05:00 We also need to say "$repeat password" equals "md5" and "$repeat password".
05:08 Here, comment this as "encrypt password". We have encrypted our password.
05:15 Now we will go ahead and add all our data into our database.
05:21 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.
05:39 Now we say 25 characters for our fullname, username, password and repeat password. So the maximum value is 25.
05:50 So, I will say- if the string length of '$username' is bigger or greater than 25.... OR
06:05 string length of the '$fullname' is greater than 25.
06:15 Let us look at these individually and say - if the length of your username or fullname is too long.
06:24 Let me put this correctly.
06:27 If each of these values is greater than 25 or bigger than 25,
06:34 we are going to echo out these values
06:40 saying "username" or... no...
06:48 Let me say "Max limit for username or fullname are 25 characters".
06:55 Otherwise I will proceed to check my password length.
07:01 Now I have decided to do this - "check password length" because I want a specific check for this.
07:12 "If string length of my password is greater than 25.. or.. string length...
07:30 No... um... let's get rid of this, get rid of else.
07:36 The first check I want to do is to see if my passwords match.
07:41 Let me say "if password equals equals (==)to repeat password" then continue the big block of code.
07:53 Otherwise echo out to the user "Your passwords do not match".
08:00 Okay?
08:03 So, you can type here and we can keep checking your character length.
08:09 Now, to check the character length of "username" and "fullname".
08:14 So, "check character length of username and fullname".
08:18 And that is going to be what we said before, if "username is greater than 25",
08:25 rather if the string length used in this function is greater than 25...
08:31 OR the string length of fullname is greater than 25, then we echo "Length of username or fullname is too long!".
08:43 So, just to keep it simple and then otherwise we will say
08:51 "check password length".
08:57 Here, I am going to specify or say if... now remember our passwords match...
09:04 So we only need to check this on one of the password variables.
09:09 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....
09:23 ...then we will echo out an error saying "Password must be between 6 and 25 characters".
09:35 This will work for sure.
09:37 We will continue this discussion in the next tutorial.
09:41 Before that, let me just conclude this with an else statement.
09:46 So, otherwise we will say "register the user".
09:51 Our code to register the user will go here.
09:56 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.
10:06 This is basically for checking a minimum or maximum limit on our password and this block of code here will be our magical "register the user" piece of code.
10:17 So join me in the next part. Bye-bye. This is Mad Madhur, dubbing for the Spoken Tutorial project.

Contributors and Content Editors

Gaurav, Gyan, PoojaMoolya, Sandhya.np14