PHP stands for "PHP: Hypertext Preprocessor" -- it is a programming language that can be used to have code executed, and stay hidden from users viewing the page. PHP can be embedded in any file with the .php extension. Any file of extension .php must still have well-formed HTML in it, but it can also have PHP. PHP code must be enclosed in <? and ?> tags. The code for PHP cannot be viewed in the source for a page because it is executed before the page is sent to the browser. Also, because of this, the php file must be viewed after a web server has served it to you, so the PHP code will be executed.
Hello!
<? echo "Hello!"; ?>
The echo command is used to output text or the contents of a variable.
When a form is submitted, the contents of the input elements is submitted. They can be accessed via "$_REQUEST['name']" as a variable (or specifically $_GET['name'] and $_POST['name']), where name is the "name" of the input element.
Firstname: <? echo $_REQUEST['firstname']; ?><br>
Lastname: <? echo $_REQUEST['lastname']; ?>
In php, one can use the "if( condition ) { statements; }" syntax to execute a portion of code only if a certain condition evaluates as true. Also one can use "else" after an if statement to branch only if the condition is not true. The if statement's condition is tested inside parenthesis, and the code that is executed is in curly braces "{ }".
<? if($_REQUEST['firstname']=="john"){
echo "I remember you, john.";
} else {
echo "I haven't met you before, " . $_REQUEST['firstname'];
}?>
The double equals signs (==) tests if two things are equal. So in this case, if the user entered 'john' in the input field of firstname on the previous page, it would output "I remember you, john." The else statement contains everything that will happen if the condition is not true, so if the user's firstname is NOT john, then it will say "I haven't met you before, [firstname]" with [firstname] as whatever they input as their first name. In an if, else if, else block one can use HTML by closing the PHP (?>) and writing HTML. It can appear messy or complicated as it becomes more detailed.
<? if($_REQUEST['firstname']=="john"){ ?>
I remember you, john.<br>
<? } else if( $_REQUEST['firstname']=="jane") { ?>
I know you, jane.<br>
<? } else { ?>
I don't know you, <? echo $_REQUEST['firstname']; ?>
<? } ?>