Ch3
Ch3
Ch3
1
Objectives
2
Introduction
• This chapter introduces three new ideas, all commonly used to create
more sophisticated web applications.
• Finally, we’ll learn how to define and use our own functions.
3
Including Multiple Files
• PHP can readily make use of external files, a capability that allow us to divide our script and
• Frequently, we will use external files to extract our HTML from our PHP or to separate out
1) Include ( )
2) Include_once ( )
3) Require ( )
4) Require_once ( )
4
Cont.
include_once(‘filename.php’);
require_once (‘/path/to/filename.html’);
Using any one of these functions has the end result of taking all the
content of the included file and dropping it in parent script at that
juncture.
5
Cont.
Include It is possible to insert the content of one PHP file into another
PHP file (before the server executes it), with the include or require
statement.
6
andling HTML Forms, Revisited
One that displays the form and another that receives it.
7
Cont.
To have one page both display and handle a form, a conditional must
9
Cont.
<html>
<body>
<form action="action.php">
First name: <input type="text" name="fname"><br>
<input type="hidden" name="country" value="Norway">
<input type="submit" value="Submit">
</form>
</body>
</html>
10
Cont.
• <html>
• <body>
• </body>
• </html>
11
Cont.
• <html>
• <body>
• </body>
• </html>
12
Making Sticky Forms
A sticky form is a standard HTML form that remembers how you filled it
out.
This is a particularly nice feature for end users, especially if you are
requiring them to resubmit a form after filling it out incorrectly in first
place.
To have PHP present that value print the appropriate variable into value
attribute of a control. e.g. :
13
Cont.
-To present the status radio buttons or check boxes, add the
code checked=“checked” to their input tag.
14
Cont.
15
Creating our own functions
function function_name( ) {
// function code
16
ating function that takes arguments
A function can take any number of argument but the order in which
you list them is critical.
function writeMsg() {
writeMsg();
17
Any Questions?
18