HTML and CSS Reference
In-Depth Information
The Server-Side PHP Script
EXAMPLE 18.16
<?php
1
extract($_REQUEST);
2
if( empty($username)){
3
echo "<span style='color:red'>Please enter your name.
</span><br />";
4
exit;
}
5
if (empty($userphone)){
echo "<span style='color:red'>Please enter your phone number.
</span><br />";
exit;
}
6
echo "Welcome <b>$username</b>. Your phone number is
<b>$userphone</b>.";
?>
EXPLANATION
1
This PHP function extracts the data from a global associative array called
$_REQUEST . It contains any name/value pairs submitted from the HTML form
and sent with either GET or POST requests; in this example, the array contains
two sets of name/value pairs:
username => “Ebenezer Scrooge”
userphone => “0207 626 4388”
PHP's extract function creates a variable, $username , for the name and assigns it
the value “Ebenezer Scrooge” and another variable called $userphone with a value
of “0207 626 4388”. (This information was sent in the server request in a param-
eter: ?username="namevalue+"&userphone="+phonevalue . Figure 18.16 shows a
completed form.
2
If the variable is empty (i.e., null), tell the user.
3
If the user didn't enter anything in the textfield, he or she will be sent this message
in red letters defined by the <span> tag (see Figure 18.17).
4
The PHP program exits here.
5
If the user doesn't type anything in the phone field, he will get a message in red
telling him or her to enter his or her phone number (see Figure 18.18).
6
The PHP program echo's a string of text to the server. The server will respond by
sending the text to the Ajax program where it will be received (line 3 in the Ajax
program) and displayed (line 4 in the Ajax program).
Search WWH ::




Custom Search