<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<?php
if(!empty($_POST)){
if(is_numeric($_POST['num1'])&&is_numeric($_POST['num2'])){
if(isset($_POST['num1'])&&isset($_POST['num2'])){
$num1=$_POST['num1'];
$num2=$_POST['num2'];
$symbol=$_POST['symbol'];
switch($symbol){
case 0:$result=$num1+$num2;break;
case 1:$result=$num1-$num2;break;
case 2:$result=$num1*$num2;break;
case 3:if($num2!=0){
$result=$num1/$num2;
}
else{
echo "值二不合法";
}
break;
}
}
else{
echo "请输入完整数据";
}
}
else{
echo "请全输入数字";
}
}
?>
<form action="" method="post">
<input type="text" name="num1" value=<?php if(isset($num1)){echo $num1;} ?>>
<select name="symbol">
<option value="0" <?php if($symbol==0){echo "selected";}?>>+</option>
<option value="1" <?php if($symbol==1){echo "selected";}?>>-</option>
<option value="2" <?php if($symbol==2){echo "selected";}?>>*</option>
<option value="3" <?php if($symbol==3){echo "selected";}?>>/</option>
</select>
<input type="text" name="num2" value=<?php if(isset($num2)){echo $num2;} ?>>
<input type="submit" value="=">
<input type="text" name="result" value=<?php if(isset($result)){echo $result;} ?>>
</form>
</body>
</html>
|
|