Welcome to part 4 of "User Registration".
We are going through these processes thoroughly.
We are using security and checks for our "username" and "password", which is really good.
If I am being confusing please let me know. Drop me an email or a comment through "youtube".
Getting into "registering our user" process.
We need to connect to our database first.
We are going to open up our table and input our values.
You might think this is very simple.
So, first of all, I am going to write a message saying "Success".
Back to our page. I'll just go back into this and check all our checks that we had created first.
So I will click "Register" and it says "Please fill in all the fields".
If I fill a variety of fields, then forget and click register its still saying a message.
So I am going to type "alex" and I am going to choose my username.
Then type my fullname and I am going to choose a password which is "abc".
The next one I will just type a mix of characters.
So, when I click register, it should say "Your passwords does not match".
So, go back to square one.
We are going to type "Alex Garrett".
We will choose a username. We are going to choose a password say "abc".
Since this is under 6 characters, when I click "Register" - "Passwords must be between 25 and 6 characters". So that check works.
Now what I will type is my fullname as "Alex Garrett" and my username as "alex".
The password is going to be just a full length password.
More than 6 characters. I will click "Register". You can see that - "Length of the username or fullname is too long!".
So you can write these checks if you want. I'll leave it up to you.
So, at the moment we have now got a successful form validation.
Now what we will do is continue with registering our user.
Now this form validation isn't good. Every time we get an error, these fields disappear; they are gone.
And the user has to retype.
So what I am going to say is, we have got our fullname, username and password variables here.
Considering this php page itself, we can incorporate php into this html code over here.
Under your fullname I am going to say "value equal to" a value inside the box and open up a phptag.
Close the php tag inside. Here I am going to echo username or rather fullname.
I will do exactly the same with our username.
So value equals, open php tags, close php tags and echo out username.
Make sure that line terminator is in there.
Now what will happen is, let's say I choose this ridiculously long name here and I choose a username say "Alex".
If you don't want your passwords to be stored. So just leave that upto the user.
I've got a too long username and it should produce this error again.
When I click register, this time its kept our fullname and username.
So it's a rule. If you get an error and you have to retype your username, your fullname, your password or your firstname, middle name, your surname; I don't know how many fields are there in your user form....
It's annoying to type your name over and over again.
So using this, your php echo inside php tags, inside the values of your html input type and it so useful and so much more convenient for the user and much more user friendly.
Okay, otherwise echo "Success!!". I have not actually given a successful form yet.
So I will type "Alex Garret" and my password is going to be over 6 characters and under 25 characters.
Click "Register". Oh! an error message. Let's see.
We have picked up an error and.... - if the string length of the password is greater than 25.....
...or the string length of the password is lesser than 6.... echo password - should be enough.... but we have run into the same problem.
I have just realized that we have an encrypted value for our password and our md5 encrypted string is massive. It's much bigger than 25 characters.
So again what I have to do is take this block of code, that has been encrypting our page. Cut out that and bring it down underneath "register the user".
So you can see from experience that order of things are very important. If you get errors like this go through your code. Look at them and realize what are you doing.
Use echo things out in between your code, just as sort as debug process.
Now I will go back to my form and I'm going to retype my perfectly acceptable password in.
Click on "Register". We have got our "Success" message.
So you see, going through your code helps to see if there are problems.
I am a bit quick at realizing these. But sometimes I pause to video, I have a look at the code and then resume the video. I don't like to keep the viewers on hold.
So you, too, will soon realize your mistakes. So we have got our "Success" and now we will say "open our database".
To do this, we need our connect variable, no you don't... I am saying my "sql connect".
And I am connecting to my local host server, which is my computer and root and my password is nothing.
I am going to say "mySQL select db". This is going to select our database. So let's say "select data base".
Even though this is obvious. This is php login and here I am going to say give a query.
So "query register" is going to be equal to "mysql_query".
This is the important part of the tutorial where we actually input our values and we register our username.
Now let me scroll down so you can see this is "INSERT INTO users".
If we go back to here, this is it "php login" is our table that we have selected. So "mySQL select db php login".
And we are inserting into "users" which is our table into the database.
And we will say values brackets, each value of the table. So each field is present into the table.
So if we go back to here and click on browse or structure - that one - we got id, name, username, password, date. So 1 2 3 4 5.
Here also we need 1 2 3 4 5. The id is auto increment, if you know from the last tutorial.
So we just need in here; the order is very important.
We have got our name, username, password, date. So this is just name, username.
This is password, no need to repeat password, that was just for check and this is going to be the date.
So these variables here, if you are not so sure, are up from here, where we have our fullname, username, password and date.
Lets change this to fullname. Okay, so this should work. After this is done I will say, "You have been registered". In fact what I am going to do is I say "die".
"You have been registered. Turn to login page".
Put this as a link back to out index page in which the user could login.
As you can see how it executes in a second and here is my previous page.
Lets say "Alex Garret". Choosing username as "alex" and this as your password. "You have been registered. Return to login page".
Now I will now check my database in "browse". You can see that I have got "Alex Garret". My id is 3 my username is "alex"
My password is my encrypted password and my date is date.
That's it. So in the next part I will show you how to tidy a few things out and test the login process.
So I'll see you there. This is Sidharth dubbing for the Spoken Tutorial project.