Nicko Gamba: Slide 1
Nicko Gamba: Slide 1
PHP
NICKO GAMBA
Slide 2
Web
page
req uest
User HTML
IT/DOES IT DO?
Web Server
PHP Loa d
results PHP file
SUMMARY
c lient
• Provid es a trem end ous a m ount
of func tiona lity to the
p rog ra m m ers
• Ca n c onnec t tra nsp a rently to
m a ny d a ta b a se system s
Slide 9
BASICS
op era tors
• Da ta typ es a nd c onversions
• Dec ision m a king if a nd switch
• Intera c ting w ith the c lient
a p p lic a tion (HTML form s)
Slide 10
• Prefixed w ith a $
• Assig n va lues w ith = op era tor:
Ex: $author = “Trevor Adams”;
PHP — • No need to d efine typ e
VARIABLES • Va ria b le na m es a re ca se
sensitive:
$author a nd $Author a re
d ifferent
Slide 12
PHP —
EXAMPLE
SCRIPT
Slide 13
PHP — <html>
LANGUAGE
<body>
<h1><?php echo “Hello World!; ?></h1>
</body>
</html>
Slide 17
IF STATEMENTS
} else {
// one or more commands if
false
}
Slide 19
STATEMENTS
//code if $choice === 0
break;
case 1:
//code if $choice === 1
break;
default: // if none was true
}
Slide 20
• Text field s
PHP—DEALING • Chec kb ox
• Ra d io b utton
WITH THE • List b oxes
CLIENT • Hid d en form field s
• Pa ssw ord b ox
• Sub m it a nd reset b uttons
Slide 23
PHP—DEALING
WITH THE
CLIENT
Slide 24
• <form method=“post”
PHP—DEALING action=“process.php” name=“data”>
• Method sp ec ifies how d a ta w ill b e sent
WITH THE •
•
Ac tion sp ec ifies the file to g o to
Id g ives the form a uniq ue na m e
WITH THE
textb ox c a lled txtName a nd the
form is sub m itted using the post
m ethod , invoking process.php.
CLIENT Process.php c ould a c c ess the
form d a ta using :
$_POST[“txtName”];
If the form used the get m ethod ,
the form d a ta w ould b e a va ila b le
as
$_GET[“txtName”];
Slide 26
WITH THE
<input type=“text” id=“txtMsg”
value=“Hello World”>
<input type=“submit” id=“submit”
CLIENT value=“Submit”>
</form>
Slide 27
CLIENT • $_GET[“inputId”];
• If a form uses the get m ethod
SUMMARY • $_POST[“inputId”];
• Ensure you set a ll ID a ttrib utes for form
elem ents a nd their c ontents
Note for slide 24th
PHP does not use the ID attribute to extract user input from the textbox—PHP ignores it.
PHP uses the name attribute to select the textbox and extract its input.
Example:
<?php
$txtInput = $_POST[“txtInput”];
?>