html代码 cal.html
<!DOCTYPE html>
<html >
<head>
<meta charset="UTF-8">
<title>我的计算器</title>
</head>
<body>
<form action="result.php" method="post">
<table width="300px" border="0">
<tr>
<td>第一个数</td>
<td><input type="text" name="num1"/></td>
</tr>
<tr>
<td>第二个数</td>
<td><input type="text" name="num2"/></td>
</tr>
<tr><td>运算符</td>
<td>
<select name="oper">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
</td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="计算结果"></td>
</tr>
</table>
</form>
</body>
</html>
php代码result.php
<?php
$num1=$_REQUEST['num1'];
$num2=$_REQUEST['num2'];
$oper=$_REQUEST['oper'];
$res=0;
switch ($oper) {
case '+':
$res =$num1+$num2;
break;
case '-':
$res =$num1-$num2;
break;
case '*':
$res =$num1*$num2;
break;
case '/':
$res =$num1/$num2;
break;
default:
echo "运算符不正确";
break;
}
echo "result is ".$res;
?>