am getting errors from this, someone should pls try to fix it and repost it with explanations....thanks
<?php
?>
<form action='<?php echo $_SERVER[PHP_SELF]?>' method='post'>
<table border='0px' style='width:250px;margin-left:auto;margin-right:auto;float:left'>
<tr><td style='width:50px'><select name='rowNumber' style='border:1px solid #666666;width:50px'>
<?php
for ($i=1;$i<=50;$i++)
{
$selected = ((isset($_POST['rowNumber']) && $_POST['rowNumber'] == $i) || (isset($_GET['rowNumber']) && $_GET['rowNumber'] == $i))?"selected":"";
print("<option value='".$i."'$selected>".$i."</option>");
}
?>
</select></td>
<td><input type='submit' name='SpecifyRows' style='width:85px;cursor:pointer' value='Specify rows'/> <input type='submit' style='width:65px;cursor:pointer' name='reset' value='Reset'/></td></tr>
</table>
</form>
<?php
class gpClassic
{
public $_num;
public $_gp;
function __construct($num)
{
$this->_num = $num;
}
function rowNum()
{
echo <<< FORM
<form action='{$_SERVER[PHP_SELF]}?applications=yes&rowNumber={$_GET[rowNumber]}' method='post'>
<table border='0px' style='width:240px;margin-left:auto;margin-right:auto;float:left;clear:both'>
<tr style='background-color:#666666;color:#ffffff;font-size:12px;text-align:center'><th style='width:20px'>S/N</th><th style='width:50px'>Unit</th><th style='width:75px'>Course Code</th><th style='width:60px'>Grade</th></tr>
FORM;
for ($us=1,$gs=1;$us<=$this->_num,$gs<=$this->_num;$us++,$gs++)
{
echo <<< FORM
<tr style='background-color:#cccccc'>
<td style='text-align:center'>{$us}.</td>
<td style='width:50px'><select name='unit{$us}' style='border:1px solid #666666;width:100%'>
<option value=''>Unit</option>
FORM;
for ($uo=1;$uo<=5;$uo++)
{
$selected = (isset($_POST[unit.$us]) && $_POST[unit.$us] == $uo)?"selected":"";
print("<option value='{$uo}' $selected>{$uo}</option>");
}
echo <<< FORM
</select></td>
<td style='text-align:center;width:75px'><input style='width:75px;border:1px solid #666666' type='text' name='courseCode{$us}' value={$_POST[courseCode.$us]} ></td>
<td style='width:60px'><select name='grade{$gs}' style='border:1px solid #666666;width:60px'>
<option value=''>Grade</option>
FORM;
for ($go=5;$go>=0;$go--)
{
$selected = (isset($_POST[grade.$gs]) && $_POST[grade.$gs] == $go && $_POST[grade.$gs] != "")?"selected":"";
print("<option value='".$go."'$selected>");
if ($go == 5)
print("A$go");
elseif ($go == 4)
print("B$go");
elseif ($go == 3)
print("C$go");
elseif ($go == 2)
print("grin$go");
elseif ($go == 1)
print("E$go");
elseif ($go == 0)
print("F$go");
print("</option>");
}
print("</select></td>");
print("</tr>");
}
$calc = gpClassic::calc();
echo <<< FORM
<tr><td colspan=4 style='text-align:left'><span style='font-weight:bold'>CGPA: </span>{$calc}</td></tr>
<tr><td colspan=2 style='text-align:left'><input type='submit' name='calculate' style='cursor:pointer' value='Calculate'/></td><td colspan=2 style='text-align:right'><input type='submit' name='add' style='width:55px;cursor:pointer' value='Add'/> <input type='submit' name='rev' style='width:60px;cursor:pointer' value='Remove'/>
</td></tr>
</table>
</form>
FORM;
}
function handleError()
{
if (isset($_POST['calculate']))
{
for ($hg=1;$hg<=$this->_num;$hg++)
{
if (!isset($_POST[unit.$hg]) || $_POST[unit.$hg] == "" || !isset($_POST[courseCode.$hg]) || $_POST[courseCode.$hg] == "" || !isset($_POST[grade.$hg]) || $_POST[grade.$hg] == "")
{
return("<span style='color:red;font-family:arial;font-size:12px'>Error has occurred.</span>");
}
if (!preg_match("/^[a-zA-Z]{3}[0-9]{3}$/", $_POST[courseCode.$hg]))
{
return("<span style='color:red;font-family:arial;font-size:12px'>Invalid course code.</span>");
}
}
}
}
function calc()
{
if (isset($_POST['calculate']) && !gpClassic::handleError())
{
for ($tp=0;$tp<=$this->_num;$tp++)
{
$totalPoint[] = $_POST[unit.$tp] * $_POST[grade.$tp];
$totalUnit[] = $_POST[unit.$tp];
}
bcscale(2);
if (array_sum($totalUnit) != 0)
{
$this->_gp = bcdiv(array_sum($totalPoint), array_sum($totalUnit));
$_SESSION['gp'] = $this->_gp;
return($this->_gp);
}
else
{
return("0.00");
}
}
else
{
return(gpClassic::handleError());
}
}
function reward()
{
$gp = $_SESSION['gp'];
if ($gp == 4.50 || $gp > 4.50)
{
return("FIRST CLASS");
}
elseif (($gp == 3.50 || $gp > 3.50) && $gp < 4.50)
{
return("SECOND CLASS UPPER");
}
elseif (($gp == 2.40 || $gp > 2.40) && $gp < 3.50)
{
return("SECOND CLASS LOWER");
}
elseif (($gp == 1.50 || $gp > 1.50) && $gp < 2.40)
{
return("THIRD CLASS");
}
elseif (($gp == 1.00 || $gp > 1.00) && $gp < 1.50)
{
return("PASS");
}
}
}
if (isset($_POST['SpecifyRows']))
{
$_GET['rowNumber'] = $_POST['rowNumber'];
$instance = new gpClassic($_POST['rowNumber']);
$instance->rowNum();
}
else if (isset($_POST['calculate']))
{
$instance = new gpClassic($_GET['rowNumber']);
$instance->rowNum();
}
elseif (isset($_POST['reset']))
{
unset($_SESSION['gp']);
$instance = new gpClassic($_POST['rowNumber']);
$instance->rowNum();
}
else
{
if (isset($_POST['rev']) && $_GET['rowNumber'] >= 2)
{
$_GET['rowNumber'] = $_GET['rowNumber'] - 1;
$instance = new gpClassic($_GET['rowNumber']);
$instance->rowNum();
}
else
{
$_GET['rowNumber'] = $_GET['rowNumber'] + 1;
$instance = new gpClassic($_GET['rowNumber']);
$instance->rowNum();
}
}
?>
<?php
?>
<form action='<?php echo $_SERVER[PHP_SELF]?>' method='post'>
<table border='0px' style='width:250px;margin-left:auto;margin-right:auto;float:left'>
<tr><td style='width:50px'><select name='rowNumber' style='border:1px solid #666666;width:50px'>
<?php
for ($i=1;$i<=50;$i++)
{
$selected = ((isset($_POST['rowNumber']) && $_POST['rowNumber'] == $i) || (isset($_GET['rowNumber']) && $_GET['rowNumber'] == $i))?"selected":"";
print("<option value='".$i."'$selected>".$i."</option>");
}
?>
</select></td>
<td><input type='submit' name='SpecifyRows' style='width:85px;cursor:pointer' value='Specify rows'/> <input type='submit' style='width:65px;cursor:pointer' name='reset' value='Reset'/></td></tr>
</table>
</form>
<?php
class gpClassic
{
public $_num;
public $_gp;
function __construct($num)
{
$this->_num = $num;
}
function rowNum()
{
echo <<< FORM
<form action='{$_SERVER[PHP_SELF]}?applications=yes&rowNumber={$_GET[rowNumber]}' method='post'>
<table border='0px' style='width:240px;margin-left:auto;margin-right:auto;float:left;clear:both'>
<tr style='background-color:#666666;color:#ffffff;font-size:12px;text-align:center'><th style='width:20px'>S/N</th><th style='width:50px'>Unit</th><th style='width:75px'>Course Code</th><th style='width:60px'>Grade</th></tr>
FORM;
for ($us=1,$gs=1;$us<=$this->_num,$gs<=$this->_num;$us++,$gs++)
{
echo <<< FORM
<tr style='background-color:#cccccc'>
<td style='text-align:center'>{$us}.</td>
<td style='width:50px'><select name='unit{$us}' style='border:1px solid #666666;width:100%'>
<option value=''>Unit</option>
FORM;
for ($uo=1;$uo<=5;$uo++)
{
$selected = (isset($_POST[unit.$us]) && $_POST[unit.$us] == $uo)?"selected":"";
print("<option value='{$uo}' $selected>{$uo}</option>");
}
echo <<< FORM
</select></td>
<td style='text-align:center;width:75px'><input style='width:75px;border:1px solid #666666' type='text' name='courseCode{$us}' value={$_POST[courseCode.$us]} ></td>
<td style='width:60px'><select name='grade{$gs}' style='border:1px solid #666666;width:60px'>
<option value=''>Grade</option>
FORM;
for ($go=5;$go>=0;$go--)
{
$selected = (isset($_POST[grade.$gs]) && $_POST[grade.$gs] == $go && $_POST[grade.$gs] != "")?"selected":"";
print("<option value='".$go."'$selected>");
if ($go == 5)
print("A$go");
elseif ($go == 4)
print("B$go");
elseif ($go == 3)
print("C$go");
elseif ($go == 2)
print("grin$go");
elseif ($go == 1)
print("E$go");
elseif ($go == 0)
print("F$go");
print("</option>");
}
print("</select></td>");
print("</tr>");
}
$calc = gpClassic::calc();
echo <<< FORM
<tr><td colspan=4 style='text-align:left'><span style='font-weight:bold'>CGPA: </span>{$calc}</td></tr>
<tr><td colspan=2 style='text-align:left'><input type='submit' name='calculate' style='cursor:pointer' value='Calculate'/></td><td colspan=2 style='text-align:right'><input type='submit' name='add' style='width:55px;cursor:pointer' value='Add'/> <input type='submit' name='rev' style='width:60px;cursor:pointer' value='Remove'/>
</td></tr>
</table>
</form>
FORM;
}
function handleError()
{
if (isset($_POST['calculate']))
{
for ($hg=1;$hg<=$this->_num;$hg++)
{
if (!isset($_POST[unit.$hg]) || $_POST[unit.$hg] == "" || !isset($_POST[courseCode.$hg]) || $_POST[courseCode.$hg] == "" || !isset($_POST[grade.$hg]) || $_POST[grade.$hg] == "")
{
return("<span style='color:red;font-family:arial;font-size:12px'>Error has occurred.</span>");
}
if (!preg_match("/^[a-zA-Z]{3}[0-9]{3}$/", $_POST[courseCode.$hg]))
{
return("<span style='color:red;font-family:arial;font-size:12px'>Invalid course code.</span>");
}
}
}
}
function calc()
{
if (isset($_POST['calculate']) && !gpClassic::handleError())
{
for ($tp=0;$tp<=$this->_num;$tp++)
{
$totalPoint[] = $_POST[unit.$tp] * $_POST[grade.$tp];
$totalUnit[] = $_POST[unit.$tp];
}
bcscale(2);
if (array_sum($totalUnit) != 0)
{
$this->_gp = bcdiv(array_sum($totalPoint), array_sum($totalUnit));
$_SESSION['gp'] = $this->_gp;
return($this->_gp);
}
else
{
return("0.00");
}
}
else
{
return(gpClassic::handleError());
}
}
function reward()
{
$gp = $_SESSION['gp'];
if ($gp == 4.50 || $gp > 4.50)
{
return("FIRST CLASS");
}
elseif (($gp == 3.50 || $gp > 3.50) && $gp < 4.50)
{
return("SECOND CLASS UPPER");
}
elseif (($gp == 2.40 || $gp > 2.40) && $gp < 3.50)
{
return("SECOND CLASS LOWER");
}
elseif (($gp == 1.50 || $gp > 1.50) && $gp < 2.40)
{
return("THIRD CLASS");
}
elseif (($gp == 1.00 || $gp > 1.00) && $gp < 1.50)
{
return("PASS");
}
}
}
if (isset($_POST['SpecifyRows']))
{
$_GET['rowNumber'] = $_POST['rowNumber'];
$instance = new gpClassic($_POST['rowNumber']);
$instance->rowNum();
}
else if (isset($_POST['calculate']))
{
$instance = new gpClassic($_GET['rowNumber']);
$instance->rowNum();
}
elseif (isset($_POST['reset']))
{
unset($_SESSION['gp']);
$instance = new gpClassic($_POST['rowNumber']);
$instance->rowNum();
}
else
{
if (isset($_POST['rev']) && $_GET['rowNumber'] >= 2)
{
$_GET['rowNumber'] = $_GET['rowNumber'] - 1;
$instance = new gpClassic($_GET['rowNumber']);
$instance->rowNum();
}
else
{
$_GET['rowNumber'] = $_GET['rowNumber'] + 1;
$instance = new gpClassic($_GET['rowNumber']);
$instance->rowNum();
}
}
?>