คือผมได้ลองเขียนโปรแกรมคำนวณเกรดง่ายๆ โดยรับข้อมูลผ่าน form ร่วมกับภาษา PHP ครับ script เป็นดังนี้
Code (PHP)
<form id="form1" name="form1" method="post" action="TestHonor.php">
<table width="500" border="0" cellpadding="0" cellspacing="3">
<tr>
<td width="116"><table width="500" border="0" cellpadding="0" cellspacing="3">
<tr>
<td width="116">Input your score :</td>
<td width="381"><label for="GPA"></label>
<input name="GPA" type="text" id="GPA" /></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="submit" id="submit" value="Generate" /></td>
</tr>
</table></td>
</tr>
</table>
</form>
<?php
$GPA = $_POST['GPA'];
if ($GPA >= 3.25 && $GPA < 3.50)
{print "You get the broze honor from the president with the GPA of ".$GPA;}
elseif ($GPA >= 3.50 && $GPA < 3.75)
{print "You get the silver honor from the president with the GPA of ".$GPA;}
elseif ($GPA >= 3.75 && $GPA <= 4)
{print "You get the gold honor from the president with the GPA of ".$GPA;}
elseif ($GPA > 4)
{print "It's impossible to make the GPA over 4";}
else
{print "Don't dare to think about the honor";}
?>
การรับค่า post ผมแนะนำว่าให้เช็คค่าว่างไว้ด้วยครับ Code (PHP)
<?php
if(!empty($_POST['GPA'];)){
$GPA = $_POST['GPA'];
if ($GPA >= 3.25 && $GPA < 3.50){
print "You get the broze honor from the president with the GPA of ".$GPA;
}elseif($GPA >= 3.50 && $GPA < 3.75){
print "You get the silver honor from the president with the GPA of ".$GPA;
}elseif ($GPA >= 3.75 && $GPA <= 4){
print "You get the gold honor from the president with the GPA of ".$GPA;
}elseif ($GPA > 4){
print "It's impossible to make the GPA over 4";
}else{
print "Don't dare to think about the honor";
}
}
?>