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.
Let us have a quick recap of what was done in the last part.
We have striped the tags off our "fullname" and "username".
We have stripped and encrypted our "password".
Remember this sequence for the functions, so that we are not striping off our encrypted value.
Here we are going to start our registration process.
I'll be checking the existence of all these.
Just before I do that I am going to set the "date".
Now, this is using the date function.
Inside we have "Y" for the year, "m" for the month and "d" for the date.
It's the capital "Y" for 4-digit year. If we use a small "y", it would be a 2-digit year.
So, in my database, at the moment, I have my year first, then my month and my day and these are separated by hyphens.
You can see this when we enter our database here and insert a value into "users".
We can see that the "date" is in a specific format, if we use this kind of function here.
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.
Its adjusted into that structure in my database.
Okay, so "if submit", then we need to check for existence.
I will add a comment here "check for existence".
Now, this is really easy.
All we want to do is we have to say is "if" statement and a block the code after that.
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.
Then we will say "password" and then we'll say....
Oh! I forgot the "fullname" here, so I'll add it there.
Separated these with a double ampersand sign.
The last one is "repeat password" so type that.
We are going to require all of these.
Else, we will say - echo "Please fill in" and in bold, "all fields".
We will put a paragraph break after that.
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.
So that's it. Let's just try it.
I will go back to my "register" page.
We got it here. Lets click in register.
"Please fill in all fields".
Lets type a couple of fields here.
Lets choose one of our passwords.
We will not repeat our password.
Register. Oh! repeat password....
repeat password.
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.
So, I realise what we need to do is, take out the "md5" function here.
Make sure you remove the end brackets. I will come down here and check for all of our data.
So, let me go back and try this again.
Remember it didn't work before when we didn't chose a "repeat password".
So if I didn't chose a repeat or a password we get our error.
If I again choose a value except the repeat password, we still get this error.
That's the problem. What we should say is - if everything exists then we can convert our password and repeat password.
So I will just say "password" is equal to "md5" of password".
This will encrypt our original variable value and store a new password code in the same variable.
We also need to say "repeat password" equals "md5" and "repeat password".
Here comment this as "encrypt password". We have encrypted our password.
Now we will go ahead and add all our data into our data base.
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.
Now we say 25 characters for our fullname, username, password and repeat password. So the maximum value is 25.
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
Let us look at these individually and say if the length of your username or fullname is too long.
Let me put this correctly.
If each of these values is greater than 25 or bigger than 25.
We are going to echo out these values
saying "username" or......... no....
Let me say "Max limit for username or fullname are 25 characters".
Otherwise I will proceed to check my password length.
Now I have decided to do this - "check password length" because I want a specific check for this.
"If string length of my password is greater than 25.... or.... string length.....
No... um... lets get rid of this, get rid of "else".
The first check I want to do is to see if my passwords match.
Let me say "if password equals equals to repeat password" then continue the big block of code.
Otherwise echo out to the user "Your passwords do not match".
Okay?
So, you can type here and we can keep checking your character length.
Now to check the character length of "username" and "fullname".
So, "check character length of username and fullname".
And that is going to be what we said before, "if username is greater than 25"
Rather if the string length used in this function is greater than 25...
Or the string length of fullname is greater than 25, then we echo "Length of username or fullname is too long!".
So, just to keep it simple and then otherwise we will say
"check password length".
Here I am going to specify or say "if"... now remember our passwords match...
So we only need to check this on one of the password variables.
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....
...then we will echo out an error saying "Password must be between 6 and 25 characters".
This will work for sure.
We will continue this discussion in the next tutorial.
Before that let me just conclude this with an "else" statement .
So, otherwise we will say "register the user".
Our code to register the user will go here.
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.
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.
So join me in the next part. Bye-bye. This is Mad Madhur dubbing for the Spoken Tutorial project.