A little PHP Enter the simple HTML code

  • Slides: 20
Download presentation
A little PHP

A little PHP

Enter the simple HTML code seen below

Enter the simple HTML code seen below

Enter the simple HTML/PHP code seen below

Enter the simple HTML/PHP code seen below

Notes on PHP • PHP code starts with <? php and ends with ?

Notes on PHP • PHP code starts with <? php and ends with ? > • PHP code can be placed with HTML tags, between HTML tags, etc. • To have PHP add something to the HTML page, one uses the PHP instruction print • PHP variables begin with a dollar sign • Lines of PHP code end with a semicolon

Initializing PHP variables from form input <? php $User. Name ="{$_POST['txt. Name']}"; ? >

Initializing PHP variables from form input <? php $User. Name ="{$_POST['txt. Name']}"; ? > • The code above takes the information from the txt. Name input box on the form that was sent over in the post operation and assigns it to the $User. Name variable, which is later used in a print statement to print the user’s name.

Post both pages to the alpha • Use FTP to put both pages on

Post both pages to the alpha • Use FTP to put both pages on the alpha (alpha. lasalle. edu). • PHP is an example of server-side scripting, it must be posted on a server (in particular, a PHP server) in order to work.

Simple Form

Simple Form

Result of clicking

Result of clicking

Viewing source of “handler” does not show PHP code. The PHP code is executed

Viewing source of “handler” does not show PHP code. The PHP code is executed on the server side, it prints results into the HTML code that contains it. Then that resulting HTML code is sent to the client.

Open the simple form in Visual Studio, add a select control/element. The right click

Open the simple form in Visual Studio, add a select control/element. The right click and choose Properties.

Give the select element (drop-down list) a name and an Id.

Give the select element (drop-down list) a name and an Id.

Add option tags between the select tags. The value of an option is what

Add option tags between the select tags. The value of an option is what it will send to the server. The text between the two tags is what will show on the page.

New PHP to handle drop-down list • ? >

New PHP to handle drop-down list • ? >

Updated form

Updated form

Result of updated form handler Note that it’s the value and not the text

Result of updated form handler Note that it’s the value and not the text that comes over.

Add a text input for the user to enter an email address, give it

Add a text input for the user to enter an email address, give it the name (and id) txt. Email

Add new PHP code to email message

Add new PHP code to email message

The mail function • The mail function has up to four arguments: – The

The mail function • The mail function has up to four arguments: – The address the message will be sent to – The subject of the message – The body of the message – Some extra stuff (including the return address and a formatting statement indicating that the email will use HTML format

PHP Concatenation $body = "<html><body><p>Username: ". $User. Name. "</p>"; $body = $body. "<p>Team Member:

PHP Concatenation $body = "<html><body><p>Username: ". $User. Name. "</p>"; $body = $body. "<p>Team Member: ". $Team. Name. "</p></body></html>"; • In PHP the concatenation operator used to make longer strings from smaller strings is a period

For credit • To get credit for this lab, show me the form (on

For credit • To get credit for this lab, show me the form (on the alpha or gamma), the HTML page that results from the handler, and the resulting email message (it may go to the Junk folder).