PHP Intro
PHP Intro
Arithmetic
Assignment
Comparison
Logical
PHP Operators
PHP Operators
PHP Operators
PHP Operators
PHP Conditional Statements
Very often when you write code, you want to perform
different actions for different decisions. You can use
conditional statements in your code to do this.
In PHP we have the following conditional statements:
if statement - use this statement to execute some code only if a
specified condition is true
if...else statement - use this statement to execute some code if
a condition is true and another code if the condition is false
if...elseif....else statement - use this statement to select one of
several blocks of code to be executed
switch statement - use this statement to select one of many
blocks of code to be executed
PHP Conditional Statements
The following example will output "Have a nice
weekend!" if the current day is Friday:
PHP Conditional Statements
Use the if....else
statement to execute
some code if a condition
is true and another code
if a condition is false.
PHP Conditional Statements
If more than one line
should be executed if a
condition is true/false, the
lines should be enclosed
within curly braces { }
PHP Conditional Statements
Notice how the URL carries the information after the file name.
PHP Forms - $_GET Function
The "welcome.php" file can now use the $_GET
function to collect form data (the names of the form
fields will automatically be the keys in the $_GET array)
PHP Forms - $_GET Function
When using method="get" in HTML forms, all variable
names and values are displayed in the URL.
This method should not be used when sending passwords
or other sensitive information!
However, because the variables are displayed in the URL, it
is possible to bookmark the page. This can be useful in some
cases.
The get method is not suitable for large variable values; the
value cannot exceed 100 chars.
PHP Forms - $_POST Function
The built-in $_POST function is used to collect values
from a form sent with method="post".
Information sent from a form with the POST method
is invisible to others and has no limits on the amount
of information to send.
Note: However, there is an 8 Mb max size for the
POST method, by default (can be changed by setting
the post_max_size in the php.ini file).
PHP Forms - $_POST Function