<?php
session_start(); // starts the session first to avoid any header errors
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Exercise 1</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<font face="Verdana, Arial, Helvetica, sans-serif">
<h1>Grade point scale converter</h1>
<?php
// variables declared below
$grade = $_POST['grade'];
$selection = $_POST['selection'];
?>
<!-- simple form to allow the user to select either undergraduate, hnd or masters -->
<form name="form1" method="post" action="<?php echo $PHP_SELF;?>">
<table>
<tr><td><input type="text" name="grade"></td>
<td><select name="selection">
<option value="undergraduate">Undergraduate</option>
<option value="hnd">HND</option>
<option value="masters">Masters</option>
</select></td>
<td><input type="submit" name="submit"></td>
</table>
</form>
<?php
// each line below has the code to determine what will happen when a user selects a value with either undergraduate, masters or hnd. If the first statement isn't true then elseif's are used for each alternate statement
if ($grade >= "70" && $selection == "undergraduate")
{
echo "Grade points: 13-15, First Class Honours";
}
elseif ($grade >= "60" && $grade <= "69" && $selection == "undergraduate")
{
echo "Grade points: 10-12, Upper Second Class Honours";
}
elseif ($grade >= "50" && $grade <= "59" && $selection == "undergraduate")
{
echo "Grade points: 7-9, Lower Second Class Honours";
}
elseif ($grade >= "40" && $grade <= "49" && $selection == "undergraduate")
{
echo "Grade points: 4-6, Third Class Honours";
}
elseif ($grade >= "0" && $grade <= "39" && $selection == "undergraduate")
{
echo "Grade points: 0-3, You have failed";
}
elseif ($grade >= "70" && $selection == "hnd")
{
echo "Grade points: 13-15, Distinction";
}
elseif ($grade >= "53" && $grade <= "69" && $selection == "hnd")
{
echo "Grade points: 8-12, Merit";
}
elseif ($grade >= "40" && $grade <= "52" && $selection == "hnd")
{
echo "Grade points: 4-7, Pass";
}
elseif ($grade >= "0" && $grade <= "39" && $selection == "hnd")
{
echo "Grade points: 1-3: You have failed";
}
elseif ($grade >= "70" && $selection == "masters")
{
echo "Grade points: 13-15, Distinction";
}
elseif ($grade >= "60" && $grade <= "69" && $selection == "masters")
{
echo "Grade points: 10-12, Pass With merit";
}
elseif ($grade >= "50" && $grade <= "59" && $selection == "masters")
{
echo "Grade points: 7-9, Pass";
}
elseif ($grade >= "40" && $grade <= "49" && $selection == "masters")
{
echo "Grade points: 4-6, Compensatable Failure";
}
elseif ($grade >= "0" && $grade <= "39" && $selection == "masters")
{
echo "Grade points 1-3, You have failed";
}
else
{
}
?>
</font>
</body>
</html>