PHP-and-MySQL/C4/User-Registration-Part-4/English

From Script | Spoken-Tutorial
Jump to: navigation, search
Time Narration
0:00 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.
0:10 If I am being confusing please let me know. Drop me an email or a comment through "youtube".
0:20 Getting into "registering our user" process.
0:23 We need to connect to our database first. We are going to open our table and input our values.
0:29 You might think this is very simple.
0:33 So, first of all, I am going to write a message saying "Success".
0:39 Back to our page. I'll just go back into this and check all our checks that we had created first.
0:48 So I will click "Register" and it says "Please fill in all the fields".
0:55 If I fill a variety of fields, then forget and click register its still saying a message.
1:04 So I am going to type "alex" and am going to choose my username. Then type my fullname and I am going to choose a password which is "abc".
1:16 The next one I will just type a mix of characters. So, when I click register, it should say "Your passwords does not match".
1:26 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".
1:40 Since this is under 6 characters, when I click "Register" - "Passwords must be between 25 and 6 characters". So that check works.
1:52 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.
02:05 More than 6 characters. I will click "Register". You can see that - "Length of the username or fullname is too long!".
2:15 So you can write these checks if you want. I'll leave it up to you.
2:20 So, at the moment we have now got a successful form validation.
2:27 Now what we will do is continue with registering our user.
2:32 Now this form validation isn't good. Every time we get an error, these fields disappear; they are gone.
2:40 And the user has to retype.
2:43 So what I am going to say is, we have got our fullname, username and password variables here.
2:50 Considering this php page itself, we can incorporate php into this html code over here.
2:58 Under your fullname I am going to say "value equal to" a value inside the box and open up a phptag.
3:07 Close the php tag inside. Here I am going to echo username or rather fullname.
3:12 I will do exactly the same with our username. So value equals, open php tags, close php tags and echo out username.
3:23 Make sure the line terminator is in there.
3:28 Now what will happen is, let's say I choose this ridiculously long name here and choose a username say "alex".
3:37 If You don't want your passwords to be stored. So just leave that upto the user.
3:43 I've got a too long username and it should produce this error again.
3:49 When I click register, this time its kept our fullname and username.
3.55 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....
4:10 It's annoying to type your name over and over again.
4:14 So using this, your php echo inside php tags, inside the values of your html input type and it so useful and much more convenient for the user and much more user friendly.
4.28 Okay, otherwise echo "Success!!". I have not actually given a successful form yet.
4:35 So I will type "Alex Garret" and my password is going to be over 6 characters and under 25 characters.
4:44 Click "Register". Oh! an error message. Let's see.
4:50 We have picked up an error and.... - if string length of the password is greater than 25.....
4:56 ...or the string length of the password is lesser than 6.... echo password - should be enough.... but we have to run into the same problem.
5:05 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.
5:19 So again what I have to do is take this block of code, that has been encrypted our test. Cut out that and bring it down underneath "register the user".
5:31 So you can see from experience that ordering of things are very important. If you get errors like this go through your code.Look at them and realise what are you doing.
5:43 User echo things out in between your code, just as a sort of debug process.
5:49 Now I will go back to my form and I'm going to retype my perfectly acceptable password in.
5:56 Click on "Register". We have got our "Success" message.
6:03 So you see, going through your code helps to see if there are problems.
6:07 I am a bit quick at realising these. But sometimes I pause the video, have a look at the code and then resume the video. I don't like to keep the viewers on hold.
6:20 So You, too, will soon realise your mistakes. So we have got our "Success" and now we will say "open our database".
6:29 To do this, we need our connect variable, no you don't... I am going to say my "sql connect".
6:37 And am connecting to my local host server, which is my computer and root and my password is nothing.
6:45 I am going to say "mySQL select db". This is going to select our database. So let's say "select data base".
6:55 Even though this is obvious. This is php login and here I am going to say give a query.
7:04 So "query register". This is going to be equal to "mysqlL query".
7:11 This is the important part of this tutorial where we actually input our values and we register our username.
7:18 Now let me scroll down so you can see this . This is "INSERT INTO users". If we go back to here, this is it "php login" is our table that we have to select . So "mySQL select db php login".
7:38 And we are inserting into "users" which is our table into the database.
7:44 And we will say values brackets, each value of the table. So each field is present into the table.
7:52 So if we go back till here and click on browse or structure - that one - we got id, name, username, password, date. So 1 2 3 4 5.
8:05 Here also we need 1 2 3 4 5. The id is auto increment, if you know from the last tutorial.
8:14 So we need in here; the order is very important.
8:18 We have got our name, username, password, date. So this is just name, username. This is password, no need to repeat password, that is just for check and this is going to be the date.
8:33 So these variables here, if you are not too sure, are from up here, where we have our fullname, username, password and date.
8:44 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".
8:57 "You have been registered return to login page". Put this as a link back to out index page in which the user could login.
9:10 You can see how it executes in a second and here is my previous page.
9:16 Lets say "Alex Garret". Choosing username as "alex" and this as your password. "You have been registered. Return to login page".
9:26 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"
9:37 My password is my encrypted password and my date is date.
9:4 That's it. So in the next part I will show you how to tidy a few things out and test the login process.
9:50 So I'll see you there. This is Siddharth dubbing for the Spoken Tutorial project.

Contributors and Content Editors

Pravin1389