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

From Script | Spoken-Tutorial
Revision as of 16:44, 25 October 2013 by Gyan (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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:18 Getting onto "registering our user" process.
0:21 We need to connect to our database first. We are going to open up 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:52 So I will click "Register" and it says "Please fill in all fields".
0:56 If I fill a variety of fields, then forget one and click register its still saying a message.
1:01 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:11 The next one I will just type a mix of characters. So, when I click register, it should say "Your passwords do not match".
1:20 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:29 Since this is under 6 characters, when I click "Register" - "Passwords must be between 25 and 6 characters". So that check works.
1:41 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.
1:54 More than 6 characters. I will click "Register". You can see that - "Length of the username or fullname is too long!".
2:01 So you can write these checks if you want. I'll leave it up to you.
2:05 So, at the moment we have now got a successful form validation.
2:11 Now what we will do is continue with registering our user.
2:17 Now this form validation isn't good. Every time we get an error, these fields disappear; they are gone.
2:31 And the user has to retype.
2:33 So what I am going to say is, we have got our fullname, username and password variables here.
2:42 Considering this is a php page itself, we can incorporate php into this html code over here.
2:52 Under your fullname I am going to say "value equal to" a value inside the box and open up a phptag.
2:58 Close the php tag inside. Here I am going to echo username or rather fullname.
3:07 I will do exactly the same with our username. So value equals, open php tags, close php tags and echo out username.
3:22 Make sure the line terminator is in there.
3:25 Now what will happen is, let's say I choose this ridiculously long name here and choose a username say "alex".
3:34 You don't want your passwords to be stored. So just leave that upto the user.
3:41 I've got a too long username and it should produce this error again.
3"44 When I click register, this time its kept our fullname and username.
3.51 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:04 It's annoying to type your name over and over again.
4:08 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.22 Okay, otherwise echo "Success!!". I have not actually given a successful form yet.
4:29 So I will type "Alex Garret" and my password is going to be over 6 characters and under 25 characters.
4:37 Click "Register". Oh! an error messge. Let's see.
4:40 We have picked up an error and.... - if string length of the password is greater than 25.....
4:48 ...or the string length of the password is lesser than 6.... echo password - should be enough.... but we have run into the same problem.
5:03 I have just realised that we have an encrypted value for our password. And our md5 encrypted string is massive. It's much bigger than 25 characters.
5:14 So again what I will do is take this block of code, that has been encrypting our password. Cut out that and bring it down underneath "register the user".
5:26 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 realise what are you doing.
5:34 Use echo things out in between your code, just as a sort of debug process.
5:41 Now I will go back to my form and I'm going to retype my perfectly acceptable password in.
5:46 Click on "Register". We have got our "Success" message.
5:50 So you see, going through your code helps to see if there are problems.
5:56 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:02 You, too, will soon realise your mistakes. So we have got our "Success" and now we will say "open our database".
6:13 To do this, we need our connect variable, no you don't... I am going to say my "sql connect".
6:20 And am connecting to my local host server, which is my computer and root and my password is nothing.
6:31 I am going to say "mySQL select db". This is going to select our database. So let's say "select data base".
6:38 Even though this is obvious. This is php login and here I am going to say give a query.
6:49 So "query register". This is going to be equal to "mysqlL query".
6:54 This is the important part of this tutorial where we actually input our values and we register our username.
7:02 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".
7:20 And we are inserting into "users" which is our table into the database.
7:28 And we will say values brackets, each value of the table. So each field that is present into the table.
7:40 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.
7:52 Here also we need 1 2 3 4 5. The id is auto increment, if you know from the last tutorial.
8:00 So we just need in here; the order is very important.
8:06 We have got our name, username, password, date. So this is just name, username. This is password, no need for repeat password, that was just for check and this is going to be the date.
8:19 So these variables here, if you are not too sure, are from up here, where we have our fullname, username, password and date.
8:28 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 say "die".
8:48 "You have been registered. Click here to return to login page". Put this as a link back to out index page in which the user could login.
9:08 You can see how it executes in a second and here is my previous page.
9:14 Lets say "Alex Garret". Choosing username as "alex" and this as your password. "You have been registered. Return to login page".
9:32 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:42 My password is my encrypted password and my date is date.
9:45 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:52 So I'll see you there. This is __________ dubbing for the Spoken Tutorial project.

Contributors and Content Editors

Gyan, PoojaMoolya, Sandhya.np14