<?php
$dy=$_POST["dy"];
$de=$_POST["de"];
$jsf=$_POST["select"];
$qingkong=$_POST["qingkong"];
$Submit=$_POST["Submit"];
if($jsf=="jia"){
$zhi=$dy+$de;
$zhi="你的計算結果為:$zhi";
}
if($jsf=="jian"){
$zhi=$dy-$de;
$zhi="你的計算結果為:$zhi";
}
if($jsf=="chen"){
$zhi=$dy*$de;
$zhi="你的計算結果為:$zhi";
}
if($jsf=="chu"){
if($de=="0"){
$zhi="被除數不能為0,請從新輸入有效的數字!";
}else{
$zhi=$dy/$de;
$zhi="你的計算結果為:$zhi";
}
}
if($jsf=="yu"){
if($de=="0"){
$zhi="求余數不能為0";
}else{
$zhi=$dy%$de;
}
}
if($qingkong=="清空"){
unset($dy,$de,$zhi);
}
?>
<html>
<head><title>計數器</title></head>
<body>
<form method="post" action="">
<table border="1">
<caption align="center">簡單計算器</caption>
<tr>
<td height="75">
<input type="text" value="<?php echo $dy; ?>" name="dy" />
</td>
<td>
<select name="select">
<option value="jia">+</option>
<option value="jian">-</option>
<option value="chen">*</option>
<option value="chu">/</option>
<option value="yu">%</option>
</select>
</td>
<td>
<input type="text" value="<?php echo $de; ?>" name="de" />
</td>
<td>
<input type="submit" name="Submit" value="提交" />
<input type="submit" name="qingkong" value="清空" />
</td>
</tr>
<tr>
<td height="23" colspan="4"><?php echo $zhi; ?></td>
</tr>
</table>
</form>
</body>
</html>