Welcome to the second part of the User registration tutorial.
In this part we will check the existence of these forms. Let us just get rid of these values in these fields that we've typed.
And we are going to do the encrypting of the password.
We are also going to move html tags.
Consider I am encrypting for my login part... Let me just open this file "login dot php".... And we will have to make a few adjustments to my page here.
We would be taking a password straight for our database.
So we need to change this "dbusername" value and our "dbpassword".
If you have not watched the 1st video you need to do so, to be able to write this code out.
Back to our "register dot php" and first of all we will check for "submit".
I don't have a "submit" variable at the moment.
So this will be equal to "dollar sign underscore POST" and now "submit".
This is because when the user clicks the submit button here, this will hold a value of "Register".
And this will say "if the user has clicked this button", then we can carry on with our code.
Now, the other values we need to get are the name of the user. So, the fullname of the user. I will just type "fullname = $ underscore POST" and "fullname". You can just see evidence of this here .
So, we are just mimicking the name given over here, once we have got fullname, username, password, repeat pasword, okay?
So, we have got "fullname" and now we have "username".
What I will do is, whenever I code, I copy and paste these down.
So "pasword" and "repeat password". Here is the "password" and "repeat password". I'm going to change these values. No need to type them out.
If you are new to php I would suggest that you type these out again and again just for practice. So you won't forget them.
So we have got all our values here.
So, if "submit". I'll just echo them out to show you that all these have been submitted correctly.
I suggest you do this for debugging. You might have spelt something wrong and its no good if you are trying to put data which is spelt wrong into your database.
Here I will say echo the "username" and forward slash and "password". Then "repeat password" and then "fullname" of the user followed by the line terminator.
So we have got all the data here that we have extracted from our form.
So I will just comment this as "form data".
You should now know how to do this by now.
If the form has been submitted, I am going to echo this out, to make sure it is there.
Here if I click "Register" nothing happens. I have been clicking and nothing is being done.
So here I will just type my full name and I can type my username and choose a password which will be "abc" for now.
Click on "Register" and nothings happened.
So "if submit", "POST submit".
This is why. In our "form action" we need to set a "method" which is going to be "POST".
I forgot to include that.
We need a method of "POST" otherwise it's default as "GET". Yes, you can see it all up here.
What I will do now is refresh this page and retype my data.
So that's "Alex Garrett" and username "alex". This will be "abc" and "abc". Click on "Register" and my data has been shown here.
We can check if its correct. My fullname was "Alex Garrett". My username chosen was "alex" and of course "abc" here and here.
Now I want to encrypt these passwords.
And if you read up on Google or any search engine about "MD5 encryption" that's "M D 5". Let me just write this down for you. It is a very useful way of encrypting data.
Let's just get rid of this. Now everything is right. Md5's function in php takes a string or numerical value, string value or just a data value.
And this is encrypted to MD5 encryption.
Lets say I encrypt "alex" to Md5. Let's echo it out and refresh.
Don't resend the data. So it should just come straight back from here and re-click on register.
Let's go here and see if "if submit" is ok. Let's take out this condition and refresh.
So that is my name encrypted in Md5.
It's always the same length and I believe its impossible to crack unless you encrypt a string and then you compare it to your two encrypted values.
If you don't understand this I have a tutorial on "MD5 encryption". So don't worry. Just go ahead and watch it.
Now I will say "if submit" and then our code.
My fullname, username and password are fine.
I will add this "MD5 encryption" around my submitted password and repeat password.
Don't forget that.
Then if I echo out, lets say, "password" and just have a break and "repeat password".
When I go to refresh or rather when I go to submit my form, I will say my password is "abc" and my repeat password is "abc".
Register that.
You can see that my 2 encrypted passwords are identical and both of them are ready to be put in the database.
Now if you say someone hacked into your database and finds out people's passwords which is typed in as abc, they will be able to get it easily.
Let me type it here. But now they won't be able to find what it is because that's encrypted.
"strip tags". This will strip HTML tags.
When I am using my password, I will not say "strip tags" before the "md5" function.
I will use the "md5" Function to encrypt the already striped version of my password.
So that should be fine.
Let me copy and past that down there.
Ok, that's done and lets go back and see that.
I type in "html" here and for my username I say "body" and just keep my password as "abc".
Lets go and echo out "username" and just add a break.
Fullname. Echoing out all that will be typed in here.
I will just type "test" after this and "test" after this.
Now this "strip tag" function must get rid of this "html" and this "body".
You should just have "test" and "test" given to us.
Oh! We have got an error.
Lets go back and check. Didn't use the line terminator. Refresh and Resend the data.
As you can see over here, we got "test" and "test". So whatever you type in here as tag or as html tag, its just blank.
So you know some people can be funny and say my username is going to be an "image". Register. That doesn't work !
It isn't echoed up here.
But if we take say "alex" and we click "Register", its taken into account.
So that's it. In the next tutorial we will check if every single field is typed in as they are all required for registration.
Ok I'll see you in the next part. Bye. This is _________ dubbing for the Spoken Tutorial project.