1 / 21

A little PHP

This tutorial explains how to handle form inputs using PHP and HTML, including initializing variables, using GET and POST methods, and sending emails. It also covers basic HTML code and concatenation in PHP.

leachv
Download Presentation

A little PHP

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. A little PHP

  2. Enter the simple HTML code seen below

  3. Enter the simple HTML/PHP code seen below

  4. 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 (or echo) • PHP variables begin with a dollar sign • Lines of PHP code end with a semicolon

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

  6. GET versus POST

  7. Send 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.

  8. Simple Form

  9. Result of clicking

  10. 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.

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

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

  13. 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.

  14. New PHP to handle drop-down list • ?>

  15. Updated form

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

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

  18. Add new PHP code to email message

  19. 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

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

  21. For credit • To get credit for this lab, show me the form (on the alpha), the HTML page that results from the handler, and the resulting email message.

More Related