
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
- Welcome to the Course
- What is PHP?
- What Does PHP Do?
- Tools to Get Started
- Download Course Files
- Your First PHP Page
- PHP Syntax
- PHP Variables
- More Variables
- Defining Constants
- Get Your Hands Dirty
- Arrays
- Associative Arrays
- Multi-Dimensional Arrays
- Get Your Hands Dirty
- If Statements
- Else
- Else If
- Get Your Hands Dirty
- Comparison Operators
- Logical Operators
- Arithmetic Operators
- String Operators
- Assignment Operators
- While Loop
- For Loop
- Foreach Loop
- Do While Loop
- PHP Functions
- Custom Functions
- Simple Arguments
- Final Website
- Basic Layout
- Global Header & Footer
- Copyright & Hours of Operation
- Team Member Array & Template
- Menu Array & Template
- Understanding $_GET
- Menu Item Template
- Contact Form
- Understanding $_POST
- Form Validation
- Form Submission
- Upload Your Website Live
- Wrap Up
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.