Lab 05 Server Side Script (PHP)
PHP
Task : Based on Topic 8 and 9 on PHP examples, create your own exercises using different values and layout.
Task : Based on Topic 8 and 9 on PHP examples, create your own exercises using different values and layout.
Example 1 (PHP syntax)
<html> Server Side Script: PHP
<?php
echo "<h1> Hello, Malaysia. Dari Universiti Pengurusan Terkemuka ! </h1>";
?>
</html>
Example 2 (Manipulation Submitted Value)
<html><head><title>Your Favourites</title></head>
<body>
<form action="fav_lab.php" method="post">
Please enter your name :<input type="text" name="username" size="45">
<p>
Please select your favourite colour :
<input type="radio" name="colour" value="green"> Green
<input type="radio" name="colour" value="magenta"> Magenta
<input type="radio" name="colour" value="blue"> Blue </p>
<p>
Please select your favourite food :
<input type="checkbox" name="food1" value="Bubur"> Bubur
<input type="checkbox" name="food2" value="Lempeng"> Lempeng
<input type="checkbox" name="food3" value="Steak"> Steak</p>
<p>
<input type="submit" value=" Submit This Form ">
<input type="reset" value=" Clear ">
</p>
</form>
</body>
</html>
Example 3 (Condition Statement & Loop)
<?php
$num = 3; $bool = false;
if ($num == 1 and $bool == true)
echo "Test 1 success";
elseif ($num == 2 and $bool == true)
echo "Test 2 success";
elseif ($num == 2 and $bool == false)
echo "Test 3 success";
else
echo "Test 4 success";
?>
Example 4 (Function)
<?php
function make_triple($arg1, $arg2, $arg3)
{
$num = $arg1 + $arg2 + $arg3;
return $num;
}
$value = make_triple(10,15,7);
echo("The value is $value");
?>
Example 5 (Array)
<?php
$CarInfo = array("Exora", "2012", 60000);
echo $CarInfo[2]; //display value of index 2 (or 3rd element)
echo "<p>";
print_r($CarInfo); //display all index and its value
?>





Comments
Post a Comment