tutorial 1(updated)
TRANSCRIPT
8/18/2019 Tutorial 1(Updated)
http://slidepdf.com/reader/full/tutorial-1updated 1/15
Lab Work : Tutorial 1
Exercise 1
Coding:
Calculator.php<html>
<head>
<title>Calculator</title>
</head>
<body>
<form action="calc_result.php" method="post">
<fieldset><legend>Calculator:</legend>
<p><b>First Number:</b> <input type="tet" name="f!" sie="#$" malength="%$"
/></p>
<p><b>&econd Number:</b> <input type="tet" name="f#" sie="#$" malength="%$"
/></p>
</fieldset>
<di' align="left"><input type="submit" name="submit" 'alue="Calculate" /></di'></form>
</body>
</html>
calc_result.php
<html>
<head>
<title>Calculator (esult</title>
</head>
<body>
<)php
// *alidate +uantity
if ,-empty,_0&123f!3455 6
f! = _0&123f!347
8 else 6
f! = N97
echo 3<p><b>;ou forgot to enter first number-</b></p>37
8
// *alidate price
if ,-empty,_0&123f#3455 6
f# = _0&123f#347
8 else 6
f# = N97
echo 3<p><b>;ou forgot to enter second number-</b></p>37
8
// f e'erything is oay print the message.
if ,f! ?? f#5 6
// Calculate the total.
add = f! @ f#7
sub = f! A f#7
mul = f! B f#7
di' = f! / f#7
add = number_format ,add #57
sub = number_format ,sub #57
mul = number_format ,mul #57
di' = number_format ,di' #57// rint the results.
8/18/2019 Tutorial 1(Updated)
http://slidepdf.com/reader/full/tutorial-1updated 2/15
echo 31he total addition of to numbers are 3.add.3<br />1he total subtraction of
to numbers are 3.sub.3<br />1he total multiplication of to numbers are 3.
mul.3<br />1he total di'ision of to numbers are 3.di'7
8 else 6 // 0ne form element as not filled out properly.
echo 3<p><font color="red">lease go bac and fill out the form again.</font></p>37
8
)></body>
</html>
Print Screen:
Exercise 2
8/18/2019 Tutorial 1(Updated)
http://slidepdf.com/reader/full/tutorial-1updated 3/15
Coding:
<html>
<head>
<title>&ugar Con'erter</title>
</head>
<body>
<form action="" method="post">
<select name="direction">
<option 'alue="ptg" selected>ound to Dilogram </option>
<option 'alue="ptg">ound to Eram </option>
</select>
<input type="tet" name="eight" sie=""/> <br/>
<input type="&ubmit" 'alue="Con'ert"/>
</form>
</body>
</html>
<)php
if ,isset,_0&123direction345 ?? -empty,_0&123eight3455
6
direction = _0&123direction347
eight = _0&123eight347
if , - is_numeric,eight55
6
error24 = "nput is not a 'alid number."7
8
if , - isset,error55
6
if ,direction == "ptg"5
6
eight_ne = con'ert_eight,eight57
echo "eight pound co'erted to ilogram is <b>eight_ne</b>
Dilogram " 7
8
else
6
eight_ne = con'ert_eight,eighttrue57
echo "eight pound con'ert to is <b>eight_ne</b> Eram " 7
8
8
else6
foreach ,error as err5
6
echo err . 3<br />37
8
8
8
function con'ert_eight,eight pound=false5
6
if ,eight5
6
ret = eight B $.%G7 8
8/18/2019 Tutorial 1(Updated)
http://slidepdf.com/reader/full/tutorial-1updated 4/15
else
6
ret = eight B %GH. 7
8
return round,ret!57
8)>
Print Screen:
8/18/2019 Tutorial 1(Updated)
http://slidepdf.com/reader/full/tutorial-1updated 5/15
Exercise 3
Coding:
<html>
<head>
<title>Iinasour Jge</title>
</head>
<body>
<form action="" method="post">
<fieldset><legend>Knter the dinasour age:</legend>
<p><b>Jge:</b> <input type="tet" name="age" /></p>
</fieldset>
<di' align="left"><input type="submit" name="submit" 'alue="Calculate-" /></di'>
</form>
</body>
</html>
<)php
a = _0&123age347
day = a B HG7
ee = day / L7
month = day / H$7
day = number_format ,day !57
ee = number_format ,ee !57
month = number_format ,month !57
echo 3Jge of dinasour in <br />day: 3.day.3<br />ee: 3.ee.3<br />month: 3.
month7
)>
Print Screen:
8/18/2019 Tutorial 1(Updated)
http://slidepdf.com/reader/full/tutorial-1updated 7/15
Exercise 4
Coding:
<html>
<head>
<title>Circle</title>
</head>
<body>
<form action="" method="post">
<fieldset><legend>Circle:</legend>
<p><b>(adius:</b> <input type="tet" name="radius" /></p>
</fieldset>
<di' align="left"><input type="submit" name="submit" 'alue="Calculate-" /></di'>
</form>
</body>
</html>
<)php
a = _0&123radius347
perimeter = a B # B H.!%#7
area = po,a#5 B H.!%#7
perimeter = number_format ,perimeter #57
area = number_format,area #57
echo 31he ansers are <br />perimeter: 3.perimeter.3<br />area: 3.area7
)>
Print Screen:
8/18/2019 Tutorial 1(Updated)
http://slidepdf.com/reader/full/tutorial-1updated 8/15
Exercise 5
Coding:
<html>
<head>
<title>CJ(</title>
</head>
<body>
<form action="" method="post">
<fieldset><legend>Car:</legend>
<p><b>Dilometer,m5:</b> <input type="number" name="m" sie="#$" malength="%$"
/></p>
<p><b>Mours,h5:</b> <input type="number" name="h" sie="#$" malength="%$" /></p>
</fieldset>
<input type="&ubmit" 'alue="Calculate"/>
</form>
</body>
</html>
<)php
// *alidate +uantity
if ,-empty,_0&123m3455 6
m = _0&123m347
8 else 6
m = N97
echo 3<p><b>;ou forgot to enter ilometer-</b></p>37
8
// *alidate price
if ,-empty,_0&123h3455 6
h = _0&123h347
8 else 6
h = N97echo 3<p><b>;ou forgot to enter hours-</b></p>37
8
// f e'erything is oay print the message.
if ,m ?? h5 6
// Calculate the total.
total = m / h7
total = number_format ,total #57
// rint the results.
echo 31he rate to reach the destination is <b>3.total7
8 else 6 // 0ne form element as not filled out properly.
echo 3<p><font color="red">lease go bac and fill out the form again.</font></p>37
8
)>
</body>
</html>
8/18/2019 Tutorial 1(Updated)
http://slidepdf.com/reader/full/tutorial-1updated 9/15
Print Screen:
Exercise 6Coding:
<html><head>
<title>1* Channel</title>
</head>
<body>
<form action="" method="post">
<select name=3channel3>
<option 'alue=3&election3>lease &elect ;our Channel</option>
<option 'alue=3H3>H</option> <option 'alue=3!$%3>!$%</option>
<option 'alue=3!!%3>!!%</option>
<option 'alue=30thers3>0thers</option>
</select>
<di' align="left"><input type="submit" name="submit" 'alue="submit" /></di'>
</p>
</form>
</body></html>
8/18/2019 Tutorial 1(Updated)
http://slidepdf.com/reader/full/tutorial-1updated 10/15
<)php
channel = _0&123channel34 7
if ,channel == "H" 5
6
echo ";our channel is CMJNNK H : erlin" 78
elseif ,channel == "!$%" 5
6
echo ";our channel is CMJNNK !$% : aster Chef" 7
8
elseif ,channel == "!!%" 5
6 echo ";our channel is CMJNNK !!% : (eflections" 7
8
elseif ,channel == "0thers" 5
6 echo "Not my fa'orite program" 7
8
else
6
echo "Not a 'alid option." 7
8
)>
Print Screen:
Exercise !s"itc#$Coding:
<html>
<head>
<title>1* Channel</title>
</head>
<body>
<form action="" method="get">
8/18/2019 Tutorial 1(Updated)
http://slidepdf.com/reader/full/tutorial-1updated 11/15
<select name=3channel3>
<option 'alue=3&election3>lease &elect ;our Channel</option>
<option 'alue=3H3>H</option>
<option 'alue=3!$%3>!$%</option>
<option 'alue=3!!%3>!!%</option>
<option 'alue=30thers3>0thers</option>
</select>
<di' align="left"><input type="submit" name="submit" 'alue="submit" /></di'>
</p>
</form>
</body>
</html>
<)php
channel = _EK123channel34 7
sitch ,channel5 6
case 3H3:
echo ";our channel is CMJNNK H: erlin"7
brea7
case 3!$%3:
echo ";our channel is CMJNNK !$%: aster Chef"7
brea7
case 3!!%3:
echo ";our channel is CMJNNK !!%: (eflection"7
brea7
default:
echo "Not my fa'orite program" 7
8
)>
Print Screen:
8/18/2019 Tutorial 1(Updated)
http://slidepdf.com/reader/full/tutorial-1updated 13/15
Exercise % !Loo& 1$Coding:
<)php
for ,i=$7 i<!!7 i@@5 6
echo "i<br />"78
)>
Print Screen:
Exercise ' !Loo& 2$Coding:
<)php
array = array,! G O !H !L #!57
foreach ,array as 'alue5 6
echo "'alue<br />"78
)>
Print Screen:
8/18/2019 Tutorial 1(Updated)
http://slidepdf.com/reader/full/tutorial-1updated 14/15
Exercise 1( !Loo& 3$Coding:
<)php
a = range,!!$57
b = range,"a""n"57
print_r ,a57print_r ,b57
)>
Print Screen:
Exercise 11 !Loo& 4$Coding:
<)php
num = !7
hile , num <= !$ 5 6
print "num<br />"7
num @= #7
8
)>
Print Screen: