Difference between revisions of "PHP-and-MySQL/C2/If-Statement/English-timed"

From Script | Spoken-Tutorial
Jump to: navigation, search
(Created page with '{| border=1 !Time !Narration |- |0:0 |Welcome to this basic php Spoken Tutorial. Here we will discuss the 'IF' statement. |- |0:06 |If you have written code before, you would h…')
 
Line 3: Line 3:
 
!Narration
 
!Narration
 
|-
 
|-
|0:0  
+
|00:0  
 
|Welcome to this basic php Spoken Tutorial.  Here we will discuss the 'IF' statement.
 
|Welcome to this basic php Spoken Tutorial.  Here we will discuss the 'IF' statement.
 
|-
 
|-
|0:06
+
|00:06
 
|If you have written code before, you would have come across the 'IF' statement
 
|If you have written code before, you would have come across the 'IF' statement
 
|-
 
|-
|0:11
+
|00:11
 
|Its not much different in php.  I'll execute one shortly and show you
 
|Its not much different in php.  I'll execute one shortly and show you
 
|-
 
|-
|0:16
+
|00:16
 
|So, let us start.  
 
|So, let us start.  
 
|-
 
|-
|0:18
+
|00:18
 
|Okay, here is a brief about the 'IF' statement. It takes a condition.  
 
|Okay, here is a brief about the 'IF' statement. It takes a condition.  
 
|-
 
|-
|0:23
+
|00:23
 
|If the condition is True, it executes one path of code.
 
|If the condition is True, it executes one path of code.
 
|-
 
|-
|0:28
+
|00:28
 
|If it is False, it will execute another path of code.
 
|If it is False, it will execute another path of code.
 
|-
 
|-
|0:32
+
|00:32
 
|For example - this is the structure.
 
|For example - this is the structure.
 
|-
 
|-
|0:36
+
|00:36
 
|If - inside the bracket is the condition to know whether 1 equals 1.  
 
|If - inside the bracket is the condition to know whether 1 equals 1.  
 
|-
 
|-
|0:41
+
|00:41
 
|Notice I am using a double equal to sign here.  This is the comparison operator.
 
|Notice I am using a double equal to sign here.  This is the comparison operator.
 
|-
 
|-
|0:47
+
|00:47
 
|In another tutorial we're going to learn about operators.
 
|In another tutorial we're going to learn about operators.
 
|-
 
|-
|0:50
+
|00:50
 
|It reads as 'is equal to' though it is not the same as 'equals'
 
|It reads as 'is equal to' though it is not the same as 'equals'
 
|-
 
|-
|0:56
+
|00:56
 
|When we're using variables, when we want to compare, we use double equal to.
 
|When we're using variables, when we want to compare, we use double equal to.
 
|-
 
|-
|1:02
+
|01:02
 
|If you are going for the True path, you can use two curly brackets.  
 
|If you are going for the True path, you can use two curly brackets.  
 
|-
 
|-
|1:06
+
|01:06
 
|We're going to open one here.
 
|We're going to open one here.
 
|-
 
|-
|1:08
+
|01:08
 
|Our code will go in between the brackets.
 
|Our code will go in between the brackets.
 
|-
 
|-
|1:12  
+
|01:12  
 
|If its Not True, we'll say else.
 
|If its Not True, we'll say else.
 
|-
 
|-
|1:15
+
|01:15
 
|The same structure - so two curly brackets.
 
|The same structure - so two curly brackets.
 
|-
 
|-
|1:17
+
|01:17
 
|For example, if 1 equals 1 we say echo True.
 
|For example, if 1 equals 1 we say echo True.
 
|-
 
|-
|1:23  
+
|01:23  
 
|If 1 is not equal 1, what we should get when we run our file is False.
 
|If 1 is not equal 1, what we should get when we run our file is False.
 
|-
 
|-
|1:30
+
|01:30
 
|Since 1 is equal to 1 what we get when we run our file is True
 
|Since 1 is equal to 1 what we get when we run our file is True
 
|-
 
|-
|1:36
+
|01:36
 
|Let us change this, if 1 equals 2, which it doesn't, then we'll get False.
 
|Let us change this, if 1 equals 2, which it doesn't, then we'll get False.
 
|-
 
|-
|1:42
+
|01:42
 
|So we would have already created a simple program to tell us if one number equals another.
 
|So we would have already created a simple program to tell us if one number equals another.
 
|-
 
|-
|1:49
+
|01:49
 
|This is quite a silly application for a program.
 
|This is quite a silly application for a program.
 
|-
 
|-
|1:52
+
|01:52
 
|So I will just add something more.  I'll create a little program for a password access.
 
|So I will just add something more.  I'll create a little program for a password access.
 
|-
 
|-
|1:58
+
|01:58
 
|We are going to store the password in a variable here.
 
|We are going to store the password in a variable here.
 
|-
 
|-
|2:03
+
|02:03
 
|Say the password is abc.
 
|Say the password is abc.
 
|-
 
|-
|2:05
+
|02:05
 
|I am going to incorporate a variable into my IF function by saying  
 
|I am going to incorporate a variable into my IF function by saying  
 
|-
 
|-
|2:11  
+
|02:11  
 
|If password, remember double equals 'def'
 
|If password, remember double equals 'def'
 
|-
 
|-
|2:15
+
|02:15
 
|And I'll say 'Access granted'
 
|And I'll say 'Access granted'
 
|-
 
|-
|2:21
+
|02:21
 
|Sorry, I made a mistake. 'def' is the password we want to ask the user for.  'abc' is the password I'm inputting to the system.
 
|Sorry, I made a mistake. 'def' is the password we want to ask the user for.  'abc' is the password I'm inputting to the system.
 
|-
 
|-
|2:32
+
|02:32
 
|So if it doesn't equal 'def',  I'll say 'Access denied'.
 
|So if it doesn't equal 'def',  I'll say 'Access denied'.
 
|-
 
|-
|2:39
+
|02:39
 
|The password that I've inputted is 'abc'.
 
|The password that I've inputted is 'abc'.
 
|-
 
|-
|2:42
+
|02:42
 
|We're going to compare the password to 'def', which is the stored password.  
 
|We're going to compare the password to 'def', which is the stored password.  
 
|-
 
|-
|2:50
+
|02:50
 
|If this equals 'def', we're going to say 'Access granted' else 'Access denied'.
 
|If this equals 'def', we're going to say 'Access granted' else 'Access denied'.
 
|-
 
|-
|2:57
+
|02:57
 
|Lets try this.
 
|Lets try this.
 
|-
 
|-
|3:00
+
|03:00
 
|'Access denied'.  This is because the passwords do not match.
 
|'Access denied'.  This is because the passwords do not match.
 
|-
 
|-
|3:05  
+
|03:05  
 
|On this basis, you can see here that I've incorporated a variable.
 
|On this basis, you can see here that I've incorporated a variable.
 
|-
 
|-
|3:10
+
|03:10
 
|Change this to 'def' and we'll get 'Access granted'.
 
|Change this to 'def' and we'll get 'Access granted'.
 
|-
 
|-
|3:18
+
|03:18
 
|Because I have one line of code here and another one line of code here.
 
|Because I have one line of code here and another one line of code here.
 
|-
 
|-
|3:22
+
|03:22
 
|I can get rid of these curly brackets.
 
|I can get rid of these curly brackets.
 
|-
 
|-
|3:25
+
|03:25
 
|To me that looks a lot neater.
 
|To me that looks a lot neater.
 
|-
 
|-
|3:29
+
|03:29
 
|Please note - there is no point in adding curly brackets if you have only one line of code for simple IF statements like these.
 
|Please note - there is no point in adding curly brackets if you have only one line of code for simple IF statements like these.
 
|-
 
|-
|3:37
+
|03:37
 
|If you're going to have a line after line here, you'll need the curly brackets.
 
|If you're going to have a line after line here, you'll need the curly brackets.
 
|-
 
|-
|3:42
+
|03:42
 
|For example, lets set a new variable here.
 
|For example, lets set a new variable here.
 
|-
 
|-
|3:46
+
|03:46
 
|Access equals 'Allowed'
 
|Access equals 'Allowed'
 
|-
 
|-
|3:52
+
|03:52
 
|That's just basically another line of code.
 
|That's just basically another line of code.
 
|-
 
|-
|3:57
+
|03:57
 
|But when I try and run this, we get an error.  
 
|But when I try and run this, we get an error.  
 
|-
 
|-
|4:02
+
|04:02
 
|It says an unexpected T_else on line 8
 
|It says an unexpected T_else on line 8
 
|-
 
|-
|4:08
+
|04:08
 
|Lets find line 8.  Its here. The line before it is causing a problem.
 
|Lets find line 8.  Its here. The line before it is causing a problem.
 
|-
 
|-
|4:13
+
|04:13
 
|Which is why we need to add our curly brackets back in to cater for two or more lines of code.  
 
|Which is why we need to add our curly brackets back in to cater for two or more lines of code.  
 
|-
 
|-
|4:22
+
|04:22
 
|We refresh this and Access is granted.
 
|We refresh this and Access is granted.
 
|-
 
|-
|4:25
+
|04:25
 
|Now I've set a new variable,  access to be allowed.
 
|Now I've set a new variable,  access to be allowed.
 
|-
 
|-
|4:29
+
|04:29
 
|This won't be of much help.
 
|This won't be of much help.
 
|-
 
|-
|4:32
+
|04:32
 
|But I was just giving you an example.
 
|But I was just giving you an example.
 
|-
 
|-
|4:35
+
|04:35
 
|You can see this is still a single line and these are double lines and you can't mix them up.
 
|You can see this is still a single line and these are double lines and you can't mix them up.
 
|-
 
|-
|4:40
+
|04:40
 
|OK, so I've created a variable. I've incorporated it into an IF statement.  Hope this was useful.
 
|OK, so I've created a variable. I've incorporated it into an IF statement.  Hope this was useful.
 
|-
 
|-
|4:46
+
|04:46
 
|This brings us to end of this tutorial.  
 
|This brings us to end of this tutorial.  
 
|-
 
|-
|4:50
+
|04:50
 
|This is Madhu dubbing for the Spoken Tutorial Project. Thanks for watching. Bye.
 
|This is Madhu dubbing for the Spoken Tutorial Project. Thanks for watching. Bye.

Revision as of 11:02, 10 July 2014

Time Narration
00:0 Welcome to this basic php Spoken Tutorial. Here we will discuss the 'IF' statement.
00:06 If you have written code before, you would have come across the 'IF' statement
00:11 Its not much different in php. I'll execute one shortly and show you
00:16 So, let us start.
00:18 Okay, here is a brief about the 'IF' statement. It takes a condition.
00:23 If the condition is True, it executes one path of code.
00:28 If it is False, it will execute another path of code.
00:32 For example - this is the structure.
00:36 If - inside the bracket is the condition to know whether 1 equals 1.
00:41 Notice I am using a double equal to sign here. This is the comparison operator.
00:47 In another tutorial we're going to learn about operators.
00:50 It reads as 'is equal to' though it is not the same as 'equals'
00:56 When we're using variables, when we want to compare, we use double equal to.
01:02 If you are going for the True path, you can use two curly brackets.
01:06 We're going to open one here.
01:08 Our code will go in between the brackets.
01:12 If its Not True, we'll say else.
01:15 The same structure - so two curly brackets.
01:17 For example, if 1 equals 1 we say echo True.
01:23 If 1 is not equal 1, what we should get when we run our file is False.
01:30 Since 1 is equal to 1 what we get when we run our file is True
01:36 Let us change this, if 1 equals 2, which it doesn't, then we'll get False.
01:42 So we would have already created a simple program to tell us if one number equals another.
01:49 This is quite a silly application for a program.
01:52 So I will just add something more. I'll create a little program for a password access.
01:58 We are going to store the password in a variable here.
02:03 Say the password is abc.
02:05 I am going to incorporate a variable into my IF function by saying
02:11 If password, remember double equals 'def'
02:15 And I'll say 'Access granted'
02:21 Sorry, I made a mistake. 'def' is the password we want to ask the user for. 'abc' is the password I'm inputting to the system.
02:32 So if it doesn't equal 'def', I'll say 'Access denied'.
02:39 The password that I've inputted is 'abc'.
02:42 We're going to compare the password to 'def', which is the stored password.
02:50 If this equals 'def', we're going to say 'Access granted' else 'Access denied'.
02:57 Lets try this.
03:00 'Access denied'. This is because the passwords do not match.
03:05 On this basis, you can see here that I've incorporated a variable.
03:10 Change this to 'def' and we'll get 'Access granted'.
03:18 Because I have one line of code here and another one line of code here.
03:22 I can get rid of these curly brackets.
03:25 To me that looks a lot neater.
03:29 Please note - there is no point in adding curly brackets if you have only one line of code for simple IF statements like these.
03:37 If you're going to have a line after line here, you'll need the curly brackets.
03:42 For example, lets set a new variable here.
03:46 Access equals 'Allowed'
03:52 That's just basically another line of code.
03:57 But when I try and run this, we get an error.
04:02 It says an unexpected T_else on line 8
04:08 Lets find line 8. Its here. The line before it is causing a problem.
04:13 Which is why we need to add our curly brackets back in to cater for two or more lines of code.
04:22 We refresh this and Access is granted.
04:25 Now I've set a new variable, access to be allowed.
04:29 This won't be of much help.
04:32 But I was just giving you an example.
04:35 You can see this is still a single line and these are double lines and you can't mix them up.
04:40 OK, so I've created a variable. I've incorporated it into an IF statement. Hope this was useful.
04:46 This brings us to end of this tutorial.
04:50 This is Madhu dubbing for the Spoken Tutorial Project. Thanks for watching. Bye.

Contributors and Content Editors

Minal, Pratik kamble, Sandhya.np14