Difference between revisions of "PHP-and-MySQL/C4/User-Registration-Part-4/English-timed"

From Script | Spoken-Tutorial
Jump to: navigation, search
 
Line 172: Line 172:
  
 
|-
 
|-
|04.28
+
|04:28
 
|Okay, otherwise echo "Success!!".  I have not actually given a successful '''form''' yet.
 
|Okay, otherwise echo "Success!!".  I have not actually given a successful '''form''' yet.
  

Latest revision as of 18:07, 24 March 2017

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

Contributors and Content Editors

Gyan, PoojaMoolya, Sandhya.np14