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

From Script | Spoken-Tutorial
Jump to: navigation, search
(Created page with '{| border=1 !Time !Narration |- |0:00 |Hello everyone, welcome to this Spoken Tutorial, which is more of an update tutorial and not a full length video. |- |0:08 |Some one has p…')
 
 
(5 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
{| border=1
 
{| border=1
!Time
+
|'''Time'''
!Narration
+
|'''Narration'''
 +
 
 
|-
 
|-
|0:00
+
|00:00
|Hello everyone, welcome to this Spoken Tutorial, which is more of an update tutorial and not a full length video.  
+
|Hello everyone, welcome to this Spoken Tutorial which is more of an update tutorial and not a full length video.
 +
 
|-
 
|-
|0:08
+
|00:08
|Some one has pointed out to me that in my register script, I need some kind of check to note if the user has been registered or not by the username that they specify.
+
|Some one has pointed out to me that in my register script, I need some kind of check to note if the user has been registered or not by the "username" that they specify.
 +
 
 
|-
 
|-
|0:19
+
|00:19
|Let us go back to our form which is here. Here you can type your fullname. You can choose a username and a password.
+
|Let us go back to our '''form''' which is here. Here you can type your 'full name'. You can choose a 'username' and a 'password'.
 +
 
 
|-
 
|-
|0:28
+
|00:28
|I have had these values here before. Let us get rid of them for now.  
+
|I have had these values here before. Let us get rid of them for now.
 +
 
|-
 
|-
|0:33
+
|00:33
 
|But, what we want is, when we are choosing the username...
 
|But, what we want is, when we are choosing the username...
 
|-
 
|-
|0:37
+
|00:37
|For example, lets say I'm registering with the username "alex".  In the database we can see here that username "alex" already exists.
+
|for example, let's say I'm registering with the username "alex".  In the database we can see here that the username "alex" already exists.
 +
 
 
|-
 
|-
|0:44
+
|00:47
|So what we will do is check the existence of the username.  
+
|So, what we will do is check the existence of the username.  
 +
 
 
|-
 
|-
|0:49
+
|00:50
 
|If the username already exists, we are not going to let the user register because we don't want a double username.
 
|If the username already exists, we are not going to let the user register because we don't want a double username.
 +
 
|-
 
|-
|1.01
+
|01:01
 
|If I were to register here, let me put the password in and choose the username as "alex". The username "alex" is already in the database.
 
|If I were to register here, let me put the password in and choose the username as "alex". The username "alex" is already in the database.
 +
 
|-
 
|-
|1:13
+
|01:13
|Let's just change this for namesake and click registerI have been successfully registered.
+
|Let's change this for namesake and click '''Register'''.   
 +
 
 
|-
 
|-
|1:23
+
|01:20
|Let us look inside our database. We can see that we have two usernames with alex. Now this causes problems while logging in.
+
| I have been successfully registered.
 +
 
 
|-
 
|-
|1:33
+
|01:23
|The 1st occurrence of name, this one here will be logged in. And this one will be ignored. So this person really will never be able to login into the database.
+
|Let us look inside our database. We can see that we have two usernames with "alex".
 +
 
 
|-
 
|-
|1:45
+
|01:28
|So let's just delete this.  
+
|Now this causes problems while logging in.
 +
 
 
|-
 
|-
|1:48
+
|01:31
|You need to create some kind of check to see if the username already exists.
+
|The 1st occurrence of name, this one here will be logged in and this one will be ignored.  
 +
 
 
|-
 
|-
|1:53
+
|01:39
|This is incredibly easy. There are more that one method for doing it.
+
|So, this person really will never be able to login into the database.
 +
 
 
|-
 
|-
|1:59
+
|01:44
 +
|So, let's just delete this.
 +
 
 +
|-
 +
|01:48
 +
|You need to create some kind of check to see if the 'username' already exists.
 +
 
 +
|-
 +
|01:53
 +
|This is incredibly easy. There are more than one method for doing it.
 +
 
 +
|-
 +
|01:59
 
|But I am going for the simplest and probably the most effective way which is going to work.  
 
|But I am going for the simplest and probably the most effective way which is going to work.  
 +
 
|-
 
|-
|2;04
+
|02:05
 
|The first thing I want to do is, take my code to connect to my database.
 
|The first thing I want to do is, take my code to connect to my database.
 +
 
|-
 
|-
|2:11
+
|02:12
|Selecting my database. I want to take this up to just where the submit button is checked.  
+
|Selecting my database, I want to take this up to just where the 'submit' button is checked.  
 +
 
 
|-
 
|-
|2:21
+
|02:20
|So, it is just connecting to the database. I am inside here.
+
|So, this is just connecting to the database. I am inside here.
 +
 
 
|-
 
|-
|2.26
+
|02:26
|Then, under here I can start my code to check my username.  
+
|Then, under here I can start my code to check my 'username'.  
 +
 
 
|-
 
|-
|2:31
+
|02:31
|Now bear in mind that you can't put your check anywhere. For simplicity I am just going to put it here and kill the rest of the script.
+
|Now, you can't put your check anywhere. For simplicity, I am just going to put it here and '''kill''' the rest of the script.
 +
 
 
|-
 
|-
|2.30
+
|02:39
|If the username has been found, I can put it in anywhere. Take care when you are using a full length page in your website, the die function will cut off the rest of the code. So I don't recommend using this.
+
|If the 'username' has been found, I can put it in anywhere.  
 +
 
 
|-
 
|-
|2:51
+
|02:44
|I recommend casing the checks that you already have inside the next statement and not really to kill the script.
+
|Take care when you are using a full length page in your website, the '''die''' function will cut off the rest of the code. So I don't recommend using this.
 +
 
 
|-
 
|-
|3:00
+
|02:53
 +
|I recommend casing the checks that you already have inside the next statement and not really to '''kill''' the script.
 +
 
 +
|-
 +
|03:00
 
|But you will get the general idea here on how to work on what we are trying to do.  
 
|But you will get the general idea here on how to work on what we are trying to do.  
 +
 
|-
 
|-
|3:06
+
|03:06
|We need to just type a query that specifies taking a record with a particular username.
+
|We need to just type a '''query''' that specifies taking a '''record''' with a particular username.
 +
 
 
|-
 
|-
|3:18
+
|03:12
|So I will say "namecheck query" here. I will call the variable "namecheck" and this will be a mysql query.
+
|So, I will say "namecheck query" here. I will call the variable "$namecheck" and this will be a '''mysql query'''.
 +
 
 
|-
 
|-
|3.28
+
|03:21
|I will select "username" for simplicity. This is not going to select all the data.
+
|I will '''select''' "username" for simplicity. This is not going to select all the data.
 +
 
 
|-
 
|-
|3:40
+
|03:27
|So I am selecting username from users, since that's our table name here.
+
|So, I am selecting username from "users"
 +
 
 
|-
 
|-
|3:47
+
|03:35
|I am going to say where username is equal to... If we look up here username of the person that submits the form is in the variable name "username".
+
|since that's our '''table''' name here.
 +
 
 
|-
 
|-
|3:57
+
|03:39
|So we can just come down here and type "username" now.  
+
|I am going to say "WHERE username" is equal to... If we look up here, username of the person that submits the '''form''' is in the variable name "username".
 +
 
 
|-
 
|-
|4:03
+
|03:50
|Now if we choose the name "alex", this would select every record in the database that has the username "alex" and we can see there's one at the moment.  
+
|So, we can just come down here and type "username" now.  
 +
 
 
|-
 
|-
|4:13
+
|03:55
|Now if I were to specify in this case, with only one record...
+
|Now if we choose the name "alex", this would select every '''record''' in the database that has the username "alex" and we can see there's one at the moment.  
 +
 
 
|-
 
|-
|4:17
+
|04:09
 +
|Now if I were to specify in this case, with only one '''record'''.
 +
 
 +
|-
 +
|04:15
 
|If I were to specify the username as "Dale", for example, no records will be returned.
 
|If I were to specify the username as "Dale", for example, no records will be returned.
 +
 
|-
 
|-
|4:25
+
|04:20
|So therefore, the username won't exists, if no records would be returned. So we need a function to check how many records are returned.
+
|So therefore, the username won't exist, if no records would be returned. So we need a function to check how many records are returned.
 +
 
 
|-
 
|-
|4:32
+
|04:29
|You can do this by creating a count variable. Its "mysql num rows". It just returns the amount of records or rows that are contained within your query which is called "namecheck".
+
|You can do this by creating a '''$count''' variable. It's "mysql num rows".  
 +
 
 
|-
 
|-
|4:50
+
|04:36
|So lets just test this. I am going to echo out count and then kill the script. The rest of the code does not execute.
+
|It just returns the amount of records or rows that are contained within your query which is called "$namecheck".
 +
 
 
|-
 
|-
|4:57
+
|04:47
|Lets go back to register and I'll type my fullname as "alex". Fullname, then choose a username. I am going to choose "Dale".
+
|So, let's just test this. I am going to '''echo''' out '''$count''' and then '''kill''' the '''script'''.  
 +
 
 
|-
 
|-
|5:10
+
|04:53
 +
|The rest of the code does not execute.
 +
 
 +
|-
 +
|04:57
 +
|Let's go back to '''Register''' and I'll type my full name as "alex".
 +
|-
 +
|05:03
 +
|Fullname, then choose an username. I am going to choose "Dale".
 +
 
 +
|-
 +
|05:10
 
|The password won't be checked so we could skip that.
 
|The password won't be checked so we could skip that.
 +
 +
|-
 +
|05:16
 +
|But I will just put them here for the sake of it and click '''Register'''. 
 +
 +
|-
 +
|05:24
 +
|We see that we have got a value of zero that is returned.
 +
 +
|-
 +
|05:28
 +
|That's because "Dale" is not actually in the database as a 'username'.
 +
 +
|-
 +
|05:32
 +
|However, if I change this to "alex", that will be a small "a".
 +
 
|-
 
|-
|5:18
+
|05:39
|But I will just put them there for the sake of it and click Register.  We see that we have got a value of zero that is returned.
+
|We have got some strip tags.  The way to deal with case sensitivity as well, is.... so, this is another pointer..
 +
 
 
|-
 
|-
|5:29
+
|05:49
|That's because "Dale" is not actually in the data base as a username.  
+
|When we are taking the 'username' into account, what we are going to say "string  to lower" here, just to make sure that this will always convert to lowercase.
 +
 
 
|-
 
|-
|5:35
+
|06:01
|However if I change this to "alex", that will be a small "a".  
+
|Next we are going to... let me find it.... Click '''Register'''.
 +
 
 
|-
 
|-
|5:43
+
|06:08
|We have got some... strip tags.  The way to deal with case sensitivity as well, is.... so this is another pointer....
+
|We can see that the value of one is returned.  
 +
 
 
|-
 
|-
|5:53
+
|06:12
|When we are taking the username into account what we are going to say "str to lower" here, just to make sure that this will always convert to lowercase.
+
|So, the check that we were looking for here is - if this variable we are echoing out, is not equal to zero,..then we need to tell the user that the username is already registered.
 +
 
 
|-
 
|-
|6:07
+
|06:25
|Next we are going to... let me find it.... Click Register.  
+
|So, here we can create a simple '''if''' statement and our '''block'''.
 +
 
 
|-
 
|-
|6:13
+
|06:29
|We see that the value of one is returned. So the check that we were looking for here is - if this variable we are echoing out, is not equal to zero,...
+
|Then we can say, if our '$count' doesn't equal zero, meaning there is a record present under this condition where the 'username' is already specified...
 +
 
 
|-
 
|-
|6:25
+
|06:40
|...then we need to tell the user that the username is already registered.  
+
|...then we can just '''kill''' the script and say "Username already taken!" or any other message. Coming back here, let's refresh.
 +
 
 
|-
 
|-
|6:30
+
|06:50
|So here we will create a simple if statement and our block.
+
|We can choose "alex". Let me type in a password and click '''Register'''.  
 +
 
 
|-
 
|-
|6:36
+
|06:56
|Then we can say, if our count doesn't equal zero, meaning there is a record present under this condition where the username is already specified...
+
|You can see that we have got "Username already taken!" error.
 
|-
 
|-
|6:47
+
|07:00
|...then we can just kill the script and say "Username already taken" or any other message. Coming back here, lets refresh.
+
|If I was to type "Dale" and choose a new name and password and click '''Register''', we can see that it has been successfully registered into the database because the 'username' does not exists.
 +
 
 
|-
 
|-
|6:56
+
|07:15
|We can choose "alex". Let me type in a password and click register. You can see that we have got "Username already taken" error.
+
|So, I will leave it at that. You can see that we have got our registered user in.
 +
 
 
|-
 
|-
|7:07
+
|07:22
|If I was to type "Dale" and choose a new name and password and click register, we can see that it has been successfully registered into the database because the username does not exists.
+
| Add a "str to lower" function which is a really useful thing to keep everything simple.
 +
 
 
|-
 
|-
|7:24
+
|07:29
|So I will leave it at that. You can see that we have got our registered user in. Add a "str to lower" function, which is a really useful thing to keep everything simple.
+
|Or you can just use a "str to lower" function in your '''if''' statement.  
 +
 
 
|-
 
|-
|7:35
+
|07:32
|Or you can just use a "str to lower" function in your if statement. However, to keep it simple I would recommend that you convert all usernames to lowercase.
+
|However, to keep it simple I would recommend that you convert all usernames into lowercase.  
 +
 
 
|-
 
|-
|7:52
+
|07:39
 
|You need to incorporate that into a login script as well. You need to convert whatever the user is typing into the login box to lowercase.
 
|You need to incorporate that into a login script as well. You need to convert whatever the user is typing into the login box to lowercase.
 +
 
|-
 
|-
|7:55
+
|07:48
 
|I encourage you to play around with it.  That's a good way to find some errors.  
 
|I encourage you to play around with it.  That's a good way to find some errors.  
 +
 
|-
 
|-
|8:02
+
|07:53
 
|Try them but if you do need any help, please email me.  Make sure you subscribe for updates.
 
|Try them but if you do need any help, please email me.  Make sure you subscribe for updates.
 +
 
|-
 
|-
|8:07
+
|07:58
|Thanks for watching. This is __________ dubbing for the Spoken Tutorial project.
+
|Thanks for watching. This is Aravind,  dubbing for the Spoken Tutorial project.

Latest revision as of 12:33, 10 June 2015

Time Narration
00:00 Hello everyone, welcome to this Spoken Tutorial which is more of an update tutorial and not a full length video.
00:08 Some one has pointed out to me that in my register script, I need some kind of check to note if the user has been registered or not by the "username" that they specify.
00:19 Let us go back to our form which is here. Here you can type your 'full name'. You can choose a 'username' and a 'password'.
00:28 I have had these values here before. Let us get rid of them for now.
00:33 But, what we want is, when we are choosing the username...
00:37 for example, let's say I'm registering with the username "alex". In the database we can see here that the username "alex" already exists.
00:47 So, what we will do is check the existence of the username.
00:50 If the username already exists, we are not going to let the user register because we don't want a double username.
01:01 If I were to register here, let me put the password in and choose the username as "alex". The username "alex" is already in the database.
01:13 Let's change this for namesake and click Register.
01:20 I have been successfully registered.
01:23 Let us look inside our database. We can see that we have two usernames with "alex".
01:28 Now this causes problems while logging in.
01:31 The 1st occurrence of name, this one here will be logged in and this one will be ignored.
01:39 So, this person really will never be able to login into the database.
01:44 So, let's just delete this.
01:48 You need to create some kind of check to see if the 'username' already exists.
01:53 This is incredibly easy. There are more than one method for doing it.
01:59 But I am going for the simplest and probably the most effective way which is going to work.
02:05 The first thing I want to do is, take my code to connect to my database.
02:12 Selecting my database, I want to take this up to just where the 'submit' button is checked.
02:20 So, this is just connecting to the database. I am inside here.
02:26 Then, under here I can start my code to check my 'username'.
02:31 Now, you can't put your check anywhere. For simplicity, I am just going to put it here and kill the rest of the script.
02:39 If the 'username' has been found, I can put it in anywhere.
02:44 Take care when you are using a full length page in your website, the die function will cut off the rest of the code. So I don't recommend using this.
02:53 I recommend casing the checks that you already have inside the next statement and not really to kill the script.
03:00 But you will get the general idea here on how to work on what we are trying to do.
03:06 We need to just type a query that specifies taking a record with a particular username.
03:12 So, I will say "namecheck query" here. I will call the variable "$namecheck" and this will be a mysql query.
03:21 I will select "username" for simplicity. This is not going to select all the data.
03:27 So, I am selecting username from "users"
03:35 since that's our table name here.
03:39 I am going to say "WHERE username" is equal to... If we look up here, username of the person that submits the form is in the variable name "username".
03:50 So, we can just come down here and type "username" now.
03:55 Now if we choose the name "alex", this would select every record in the database that has the username "alex" and we can see there's one at the moment.
04:09 Now if I were to specify in this case, with only one record.
04:15 If I were to specify the username as "Dale", for example, no records will be returned.
04:20 So therefore, the username won't exist, if no records would be returned. So we need a function to check how many records are returned.
04:29 You can do this by creating a $count variable. It's "mysql num rows".
04:36 It just returns the amount of records or rows that are contained within your query which is called "$namecheck".
04:47 So, let's just test this. I am going to echo out $count and then kill the script.
04:53 The rest of the code does not execute.
04:57 Let's go back to Register and I'll type my full name as "alex".
05:03 Fullname, then choose an username. I am going to choose "Dale".
05:10 The password won't be checked so we could skip that.
05:16 But I will just put them here for the sake of it and click Register.
05:24 We see that we have got a value of zero that is returned.
05:28 That's because "Dale" is not actually in the database as a 'username'.
05:32 However, if I change this to "alex", that will be a small "a".
05:39 We have got some strip tags. The way to deal with case sensitivity as well, is.... so, this is another pointer..
05:49 When we are taking the 'username' into account, what we are going to say "string to lower" here, just to make sure that this will always convert to lowercase.
06:01 Next we are going to... let me find it.... Click Register.
06:08 We can see that the value of one is returned.
06:12 So, the check that we were looking for here is - if this variable we are echoing out, is not equal to zero,..then we need to tell the user that the username is already registered.
06:25 So, here we can create a simple if statement and our block.
06:29 Then we can say, if our '$count' doesn't equal zero, meaning there is a record present under this condition where the 'username' is already specified...
06:40 ...then we can just kill the script and say "Username already taken!" or any other message. Coming back here, let's refresh.
06:50 We can choose "alex". Let me type in a password and click Register.
06:56 You can see that we have got "Username already taken!" error.
07:00 If I was to type "Dale" and choose a new name and password and click Register, we can see that it has been successfully registered into the database because the 'username' does not exists.
07:15 So, I will leave it at that. You can see that we have got our registered user in.
07:22 Add a "str to lower" function which is a really useful thing to keep everything simple.
07:29 Or you can just use a "str to lower" function in your if statement.
07:32 However, to keep it simple I would recommend that you convert all usernames into lowercase.
07:39 You need to incorporate that into a login script as well. You need to convert whatever the user is typing into the login box to lowercase.
07:48 I encourage you to play around with it. That's a good way to find some errors.
07:53 Try them but if you do need any help, please email me. Make sure you subscribe for updates.
07:58 Thanks for watching. This is Aravind, dubbing for the Spoken Tutorial project.

Contributors and Content Editors

Gaurav, Gyan, PoojaMoolya, Pratik kamble, Sandhya.np14