If Statements 
If Statements
by Brad Hussey
Video Lecture 16 of 45
Not yet rated
Views: 734
Date Added: May 14, 2017

Lecture Description

Lecture 16: If Statements

The point of coding in PHP is to make your website dynamic—or smart—so that it can make logical decisions. What I mean by this is your website can make decisions on what to do next based on user input, user conditions, or parameters you've set yourself. Here are some examples:

When a user logs into their account, they must type both their username and password. What if their password is wrong? What if they didn't type a valid email address? What if they forgot to type their email address altogether? PHP can handle what to do in these situations using If, Else, and Elseif statements.
What if a customer tries to buy a product online, but that product is sold out? PHP can let the user know the product is sold out because you can program it to calculate how many items of that product are remaining.
What if a user uploads an image that is too large? PHP can compare the uploaded image with your parameters and tell the user to upload a smaller image size if it exceeds the limit.
...and so much more!
Let's start with the If Statement. It works something like this:

If THIS then THAT

Okay, that was a little vague. Let's expand on that a bit:

If expression is TRUE, then do something

If expression is FALSE, then don't do anything

What's an Expression?

You're probably wondering what an "expression" is. Here's how PHP.net explains what an expression is:

Expressions are the most important building stones of PHP. In PHP, almost anything you write is an expression. The simplest yet most accurate way to define an expression is "anything that has a value". The most basic forms of expressions are constants and variables. When you type "$a = 5", you're assigning '5' into $a. '5', obviously, has the value 5, or in other words '5' is an expression with the value of 5 (in this case, '5' is an integer constant).

DOWNLOAD COURSE FILES HERE
www.bradhussey.ca/download-php-course

Course Index

Course Description

This course is a Total Beginner's Guide to Coding Your Very Own Dynamic Websites with PHP, so you need no prior knowledge or experience — although it's a good idea that you know some HTML (my beginner's guide "Build a Website from Scratch with HTML & CSS" will get teach you everything you need to know).

So — why learn PHP? Well, PHP is a very powerful scripting language used by millions of websites. Some of the most popular websites and frameworks utilize PHP to build their dynamic websites. PHP works very well with HTML, and therefore will allow you to start coding dynamic websites quickly without having to learn some of the more complicated scripting languages out there.

Comments

There are no comments. Be the first to post one.
  Post comment as a guest user.
Click to login or register:
Your name:
Your email:
(will not appear)
Your comment:
(max. 1000 characters)
Are you human? (Sorry)