Download presentation
Presentation is loading. Please wait.
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 PHP variables begin with a dollar sign Lines of PHP code end with a semicolon
5
Initializing PHP variables from form input
$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
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.
7
Simple Form
8
Result of clicking
9
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.
10
Open the simple form in Visual Studio, add a select control/element
Open the simple form in Visual Studio, add a select control/element. The right click and choose Properties.
11
Give the select element (drop-down list) a name and an Id.
12
Add option tags between the select tags
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.
13
New PHP to handle drop-down list
?>
14
Updated form
15
Result of updated form handler
Note that it’s the value and not the text that comes over.
16
Add a text input for the user to enter an email address, give it the name (and id) txtEmail
17
Add new PHP code to email message
18
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 will use HTML format
19
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
20
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 message (it may go to the Junk folder).
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.