Uploaded by thakurjaan71

module 5 assign A php1

advertisement
PHP
1
Module_5: Assignment ‘A’
module_5_assign_A_php1.docx
Module 5: “User Defined & Built-in Functions”
Task:
Create a PHP script named perimeter.php
Using self-referencing webforms and a user-defined function,
create a small program which calculates the perimeter from
the provided user input (Sample output below)
e
o
Starting code has been provided on the next page.
Complete the code missing from the four sections by following the
instructions below:
Code Section #1:
o
Add the self-referencing condition to check whether the form has
been submitted. If it has, the calculation will be performed, if not,
the form will be displayed.
Code Section #2:
e
Create a function which calculates the parameter based upon the
user input from the form and returns the value.
Code Section #3:
e
e
Calculated the perimeter by passing the values that the user
entered into the form to the user-defined function.
Output the results.
Code Section #4:
o Display the current date on this page.
e SAVE as perimeter.php
e
UPLOAD
to your web server and TEST!
PHP
1
Module_5: Assignment ‘A’
HINTS:
Code Section #1:
e
Add the self-referencing condition to check whether the form has been
submitted. If it has, the calculation will be performed, if not, the form will be
displayed.
Hint:
if statement and isset() function required.
The else will display the form.
Code Section #2:
e
Create a function which calculates the parameter based upon the user input
from the form and returns the value.
Hint:
function getPerimeter($length, $width)
{
... caluculate $perimeter
Return “ ... message with $perimeter ... «;
}
Code Section #3:
e
e
Calculated the perimeter by passing the values that the user entered into the
form to the user-defined function.
Output the results.
Hint:
echo getPerimeter(
s
)s
Code Section #4:
e
Display the current date on this page.
Hint:
echo ... the current date (formatted) here!
e SAVE as perimeter.php
e
UPLOAD
to your web server and TEST!
PHP
1
Module_5: Assignment ‘A’
Starting Code:
KIDOCTYPE
html¥
[Khtml>
head><title>Perimeter
Calculation</title></head>
Kbody>
lkhl>Perimeter
?php
Calculation
- by
{ Your
name
}</hl>
/*k
*
#1
YOUR
CODE
GOES
HERE
x/
$name = $_POST['name'];
$rlength = $_POST['length'];
$rwidth
= $_POST['width'];
//
//
function definition
calculate perimeter
//
p
=
of
rectangle
2% (1+w)
/‘k
*
#2
YOUR
CODE
GOES
HERE
&7
echo
"Hi
$name,
<pr>";
/1’
*
#3
YOUR
CODE
GOES
HERE
GOES
HERE
X7
echo
"<pr><hr>";
/*
*
#4
YOUR
CODE
=7
}
else
{?>
<form
action="perimeter.php"
Enter
your
Name:
<input type="text"
Enter a Length:
<input type="text"
Enter
<input
<input
</form>
<?php
}
2>
/body>
K/html>|
method="post">
size="15"
id="name"
size="15"
id="length"
name="name"/><br/>
name="length"/><br/>
a Width:
type="text"
size="15" id="width" name="width"/><br/>
type="submit" name="submit" value="Submit"/>
PHP
1
Module_5: Assignment ‘A’
Sample Output:
Perimeter Calculation - by { Your name }
Enter your Name:
|Bob
Enter a Length: 4
Enter a Width: 4
Submit |
Sample Output based on Width: 4 Length: 4
Perimeter Calculation - by { Your name }
Hi Bob,
The perimeter of a rectangle of length 4 units and width 4 units is: 16 units
The current date is Tuesday January 30th, 2018
Replace with current date
Download