Question 1.
<?php
$name = "Syamsul Bahrin Zaibon";
?>
<html>
<head>
<title>Intro to PHP</title>
</head>
<body>
<h1>
<!--Basic PHP Code.
to print variable name's value --!>
Dear <?php print ($name);?> Welcome to PHP
</h1>
</body>
</html>
output:
Question 2,
<?php
$height = 150;
$width = 30;
?>
<html><head><title>Using Variables and Operators</title></head>
<body>
<h2> The output of the code: </h2><br>
<?php
$luas = $height * $width;
print ("Luas segi empat dengan panjang $height dan lebar $width ialah $luas");
?>
</body>
</html>
output:
To modify above code so that can compute and display net salary based on information give.
<?php
$salary = 2100;
$allowances = 1000;
$socso = 210;
?>
<html><head><title>Using Variables and Operators</title></head>
<body>
<h2> The output of the net salary: </h2><br>
<?php
$net = $salary + $allowances - $socso;
print ("Net Salary is $net");
?>
</body>
</html>
Question3.
<html>
<head><title>Table</title></head>
<body>
<h1>The output of the code: </h1><br>
<TABLE BORDER = "1">
<?php
for($row = 1; $row<=3; $row++)
{
print ("<TR>");//create row
for ($column =1; $column <=2; $column++)
{
print("<TD>"); //create column
print("Baris $row, Lajur $column");
print("</TD>");
}
print ("</TR>");
}
?>
</TABLE>
</body>
</html>
output:
Question 4.
Correct the code that have error in code.
a).
<html>
<head><title>Syntax</title></head>
<body>
<h1> The output of the code: </h1><br />
<?php
for ($a=1;$a<10;$a++)
{
echo $a,"\n";
}
?>
</body>
</html>
b).
<html>
<head><title>Syntax</title></head>
<body>
<h1> The output of the code: </h1><br />
Welcome <?php echo $_POST["name"];?><br>
You are <?php echo $_POST ["age"];?>years old
</body>
</html>




No comments:
Post a Comment