<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="https://script.spoken-tutorial.org/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://script.spoken-tutorial.org/index.php?action=history&amp;feed=atom&amp;title=PHP-and-MySQL%2FC2%2FIf-Statement%2FEnglish</id>
		<title>PHP-and-MySQL/C2/If-Statement/English - Revision history</title>
		<link rel="self" type="application/atom+xml" href="https://script.spoken-tutorial.org/index.php?action=history&amp;feed=atom&amp;title=PHP-and-MySQL%2FC2%2FIf-Statement%2FEnglish"/>
		<link rel="alternate" type="text/html" href="https://script.spoken-tutorial.org/index.php?title=PHP-and-MySQL/C2/If-Statement/English&amp;action=history"/>
		<updated>2026-04-06T01:11:48Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.23.17</generator>

	<entry>
		<id>https://script.spoken-tutorial.org/index.php?title=PHP-and-MySQL/C2/If-Statement/English&amp;diff=519&amp;oldid=prev</id>
		<title>Chandrika: Created page with '{| border=1 !Time !Narration |- |0:0  |Welcome to this basic php Spoken Tutorial.  Here we will discuss the 'IF' statement. |- |0:05  |If you have written code before, you would …'</title>
		<link rel="alternate" type="text/html" href="https://script.spoken-tutorial.org/index.php?title=PHP-and-MySQL/C2/If-Statement/English&amp;diff=519&amp;oldid=prev"/>
				<updated>2012-11-29T06:29:27Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;#039;{| border=1 !Time !Narration |- |0:0  |Welcome to this basic php Spoken Tutorial.  Here we will discuss the &amp;#039;IF&amp;#039; statement. |- |0:05  |If you have written code before, you would …&amp;#039;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{| border=1&lt;br /&gt;
!Time&lt;br /&gt;
!Narration&lt;br /&gt;
|-&lt;br /&gt;
|0:0 &lt;br /&gt;
|Welcome to this basic php Spoken Tutorial.  Here we will discuss the 'IF' statement.&lt;br /&gt;
|-&lt;br /&gt;
|0:05 &lt;br /&gt;
|If you have written code before, you would have come across the 'IF' statement&lt;br /&gt;
|-&lt;br /&gt;
|0:08 &lt;br /&gt;
|Its not much different in php.  I'll execute one shortly and show you&lt;br /&gt;
|-&lt;br /&gt;
|0:14&lt;br /&gt;
|So, let us start. &lt;br /&gt;
|-&lt;br /&gt;
|0:16&lt;br /&gt;
|Okay, here is a brief about the 'IF' statement. It takes a condition. &lt;br /&gt;
|-&lt;br /&gt;
|0:20 &lt;br /&gt;
|If the condition is True, it executes one path of code.&lt;br /&gt;
|-&lt;br /&gt;
|0:23 &lt;br /&gt;
|If it is False, it will execute another path of code.&lt;br /&gt;
|-&lt;br /&gt;
|0:27 &lt;br /&gt;
|For example - this is the structure.&lt;br /&gt;
|-&lt;br /&gt;
|0:32&lt;br /&gt;
|If - inside the bracket is the condition to know whether 1 equals 1. &lt;br /&gt;
|-&lt;br /&gt;
|0:37&lt;br /&gt;
|Notice I am using a double equal to sign here.  This is the comparison operator.&lt;br /&gt;
|-&lt;br /&gt;
|0:42&lt;br /&gt;
|In another tutorial we're going to learn about operators.&lt;br /&gt;
|-&lt;br /&gt;
|0:46&lt;br /&gt;
|It reads as 'is equal to' though it is not the same as 'equals'&lt;br /&gt;
|-&lt;br /&gt;
|0:55&lt;br /&gt;
|When we're using variables, when we want to compare, we use double equal to.&lt;br /&gt;
|-&lt;br /&gt;
|0:58&lt;br /&gt;
|If you are going for the True path, you can use two curly brackets. &lt;br /&gt;
|-&lt;br /&gt;
|1:02&lt;br /&gt;
|We're going to open one here.&lt;br /&gt;
|-&lt;br /&gt;
|1:04&lt;br /&gt;
|Our code will go in between the brackets.&lt;br /&gt;
|-&lt;br /&gt;
|1:07 &lt;br /&gt;
|If its Not True, we'll say else.&lt;br /&gt;
|-&lt;br /&gt;
|1:11&lt;br /&gt;
|The same structure - so two curly brackets.&lt;br /&gt;
|-&lt;br /&gt;
|1:14 &lt;br /&gt;
|For example, if 1 equals 1 we say echo True.&lt;br /&gt;
|-&lt;br /&gt;
|1:23 &lt;br /&gt;
|If 1 is not equal 1, what we should get when we run our file is False.&lt;br /&gt;
|-&lt;br /&gt;
|1:26&lt;br /&gt;
|Since 1 is equal to 1 what we get when we run our file is True&lt;br /&gt;
|-&lt;br /&gt;
|1:35&lt;br /&gt;
|Let us change this, if 1 equals 2, which it doesn't, then we'll get False.&lt;br /&gt;
|-&lt;br /&gt;
|1:41&lt;br /&gt;
|So we would have already created a simple program to tell us if one number equals another.&lt;br /&gt;
|-&lt;br /&gt;
|1:46&lt;br /&gt;
|This is quite a silly application for a program.&lt;br /&gt;
|-&lt;br /&gt;
|1:49&lt;br /&gt;
|So I will just add something more.  I'll create a little program for a password access.&lt;br /&gt;
|-&lt;br /&gt;
|1:56&lt;br /&gt;
|We are going to store the password in a variable here.&lt;br /&gt;
|-&lt;br /&gt;
|2:00 &lt;br /&gt;
|Say the password is abc.&lt;br /&gt;
|-&lt;br /&gt;
|2:05&lt;br /&gt;
|I am going to incorporate a variable into my IF function by saying &lt;br /&gt;
|-&lt;br /&gt;
|2:11 &lt;br /&gt;
|If password, remember double equals 'def'&lt;br /&gt;
|-&lt;br /&gt;
|2:14&lt;br /&gt;
|And I'll say 'Access granted'&lt;br /&gt;
|-&lt;br /&gt;
|2:20&lt;br /&gt;
|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.&lt;br /&gt;
|-&lt;br /&gt;
|2:32&lt;br /&gt;
|So if it doesn't equal 'def',  I'll say 'Access denied'.&lt;br /&gt;
|-&lt;br /&gt;
|2:38&lt;br /&gt;
|The password that I've inputted is 'abc'.&lt;br /&gt;
|-&lt;br /&gt;
|2:42&lt;br /&gt;
|We're going to compare the password to 'def', which is the stored password. &lt;br /&gt;
|-&lt;br /&gt;
|2:46&lt;br /&gt;
|If this equals 'def', we're going to say 'Access granted' else 'Access denied'.&lt;br /&gt;
|-&lt;br /&gt;
|2:54&lt;br /&gt;
|Lets try this.&lt;br /&gt;
|-&lt;br /&gt;
|2:58 &lt;br /&gt;
|'Access denied'.  This is because the passwords do not match.&lt;br /&gt;
|-&lt;br /&gt;
|3:00 &lt;br /&gt;
|On this basis, you can see here that I've incorporated a variable.&lt;br /&gt;
|-&lt;br /&gt;
|3:06&lt;br /&gt;
|Change this to 'def' and we'll get 'Access granted'.&lt;br /&gt;
|-&lt;br /&gt;
|3:13 &lt;br /&gt;
|Because I have one line of code here and another one line of code here.&lt;br /&gt;
|-&lt;br /&gt;
|3:20&lt;br /&gt;
|I can get rid of these curly brackets.&lt;br /&gt;
|-&lt;br /&gt;
|3:24&lt;br /&gt;
|To me that looks a lot neater.&lt;br /&gt;
|-&lt;br /&gt;
|3:27 &lt;br /&gt;
|Please note - there is no point in adding curly brackets if you have only one line of code for simple IF statements like these.&lt;br /&gt;
|-&lt;br /&gt;
|3:34 &lt;br /&gt;
|If you're going to have line after line here, you'll need the curly brackets.&lt;br /&gt;
|-&lt;br /&gt;
|3:39 &lt;br /&gt;
|For example, lets set a new variable here.&lt;br /&gt;
|-&lt;br /&gt;
|3:44 &lt;br /&gt;
|Access equals 'Allowed'&lt;br /&gt;
|-&lt;br /&gt;
|3:50&lt;br /&gt;
|That's just basically another line of code.&lt;br /&gt;
|-&lt;br /&gt;
|3:55 &lt;br /&gt;
|But when I try and run this, we get an error. &lt;br /&gt;
|-&lt;br /&gt;
|4:00&lt;br /&gt;
|It says an unexpected T_else on line 8&lt;br /&gt;
|-&lt;br /&gt;
|4:07 &lt;br /&gt;
|Lets find line 8.  Its here. The line before it is causing a problem.&lt;br /&gt;
|-&lt;br /&gt;
|4:11&lt;br /&gt;
|Which is why we need to add our curly brackets back in to cater for two or more lines of code. &lt;br /&gt;
|-&lt;br /&gt;
|4:20&lt;br /&gt;
|We refresh this and Access is granted.&lt;br /&gt;
|-&lt;br /&gt;
|4:23 &lt;br /&gt;
|Now I've set a new variable,  access to be allowed.&lt;br /&gt;
|-&lt;br /&gt;
|4:26&lt;br /&gt;
|This won't be of much help.&lt;br /&gt;
|-&lt;br /&gt;
|4:29 &lt;br /&gt;
|But I was just giving you an example.&lt;br /&gt;
|-&lt;br /&gt;
|4:31&lt;br /&gt;
|You can see this is still a single line and these are double lines and you can't mix them up.&lt;br /&gt;
|-&lt;br /&gt;
|4:37&lt;br /&gt;
|OK, so I've created a variable. I've incorporated it into an IF statement.  Hope this was useful.&lt;br /&gt;
|-&lt;br /&gt;
|4:42&lt;br /&gt;
|This brings us to end of this tutorial. &lt;br /&gt;
|-&lt;br /&gt;
|4:45&lt;br /&gt;
|This is Mad Madhur dubbing for the Spoken Tutorial Project. Thanks for watching. Bye.&lt;/div&gt;</summary>
		<author><name>Chandrika</name></author>	</entry>

	</feed>