This week we learned on PHP and form processing. PHP is good at handling data submitted to the server in HTML forms. Form is used to accept user input in a systematic and structured manner. There are two main attributes in a form which are method and action.
1. $_POST
Form processing with $_POST- welcome.html
welcome.html with POST method |
output |
Displaying Submitted Values- welcome.php
welcome.php with POST method |
output |
2. $_GET
Form processing with $_GET- welcome.html
welcome.html with method GET |
output |
Displaying Submitted Values- welcome.php
welcome.php with GET method |
output |
3. $_REQUEST variable: it contains contents both $_GET, $_POST and $_COOKIE. It can be used to get the result from form data sent with both the GET and POST methods.
For the lab session
We have done some discussion on past year question regarding to processing CGPA.Click to visit the link.
//retrieved information from the form
$name = $_POST["name"];
$matric = $_POST["matric"];
$stiv1023_mark = $_POST["stiv1023_mark"];
$stiv2023_mark = $_POST["stiv2023_mark"];
$stiv3013_mark = $_POST["stiv3013_mark"];
$vkhb2031_mark = $_POST["vkhb2031_mark"];
//calculate grade for each course by calling calculateGred() function
$stiv1023_gred = calculateGred($stiv1023_mark);
$stiv2023_gred = calculateGred($stiv2023_mark);
$stiv3013_gred = calculateGred($stiv3013_mark);
$vkhb2031_gred = calculateGred($vkhb2031_mark);
//calculate point for each course by calling calculatePoint() function
$stiv1023_point = calculatePoint($stiv1023_gred);
$stiv2023_point = calculatePoint($stiv2023_gred);
$stiv3013_point = calculatePoint($stiv3013_gred);
$vkhb2031_point = calculatePoint($vkhb2031_gred);
//calculate TotalPoint based on point for each course and credit
$TotalPoint = $stiv1023_point * 3 + $stiv2023_point * 3 + $stiv3013_point * 3 + $vkhb2031_point * 1;
//calculate GPA based on TotalPoint and total credit
$GPA = $TotalPoint / 10;
//calculate final result by calling calculateResult() function
$result = calculateResult($GPA);
//function to calculate the grade based on mark
function calculateGred($mark)
{
if ($mark >= 90)
$gred = "A";
else if ($mark >= 80)
$gred = "B";
else if ($mark >= 70)
$gred = "C";
else if ($mark >= 60)
$gred = "D";
else if ($mark >= 50)
$gred = "E";
else
$gred = "F";
return $gred;
}
//function to calculate the point based on grade
function calculatePoint($gred)
{
if ($gred == "A")
$point = 4.00;
else if ($gred == "B")
$point = 3.50;
else if ($gred == "C")
$point = 3.00;
else if ($gred == "D")
$point = 2.50;
else if ($gred == "E")
$point = 2.00;
else
$point = 1.00;
return $point;
}
//function to calculate the result based on GPA
function calculateResult($GPA)
{
if ($GPA >= 3.00)
$result = "Pass with distinction";
else if ($GPA >= 2.00)
$result = "Pass";
else
$result = "Fail";
return $result;
}
//to print output of the name and matric
Name: <?php echo $_POST["name"]; ?><br>
Matric: <?php echo $_POST["matric"];?>
//to display output in a Table format
<table width = "100%" border="1" cellspacing="2" cellpadding="2">
<tr>
<th align="left">Course Code</th>
<th align="left">Course Name</th>
<th align="center">Credits</th>
<th align="center">Marks</th>
<th align="center">Gred</th>
<th align="center">Point</th>
</tr>
<tr>
<td>STIV1023</td>
<td>Multimedia Foundation</td>
<td align="center">3</td>
<td align="center"><?php echo $stiv1023_mark;?></td>
<td align="center"><?php echo $stiv1023_gred;?></td>
<td align="center"><?php echo $stiv1023_point;?></td>
</tr>
<tr>
<td>STIV2023</td>
<td>Graphic & Animation</td>
<td align="center">3</td>
<td align="center"><?php echo $stiv2023_mark;?></td>
<td align="center"><?php echo $stiv2023_gred;?></td>
<td align="center"><?php echo $stiv2023_point;?></td>
</tr>
<tr>
<td>STIV3013</td>
<td>WWW Programming</td>
<td align="center">3</td>
<td align="center"><?php echo $stiv3013_mark;?></td>
<td align="center"><?php echo $stiv3013_gred;?></td>
<td align="center"><?php echo $stiv3013_point;?></td>
</tr>
<tr>
<td>VKHB2031</td>
<td>Kelana Siswa</td>
<td align="center">1</td>
<td align="center"><?php echo $vkhb2031_mark;?></td>
<td align="center"><?php echo $vkhb2031_gred;?></td>
<td align="center"><?php echo $vkhb2031_point;?></td>
</tr>
</table><br/>
<p>Total Credit: 10<br/>
Gred Point Average(GPA) = <?php echo $GPA;?><br/>
Result : <?php echo $result;?></p>
output |
No comments:
Post a Comment