<!DOCTYPE html>
<html>
<head>
<meta charset="{CHARSET}">
<title>calculator</title>
</head>
<body>
<?php
if(!empty($_POST)){
$num1 = $_POST['data1'];
$num2 = $_POST['data2'];
$fuhao = $_POST['yunsuanfu'];
if($fuhao == '+'){
$jieguo = $num1 + $num2;
}
else if($fuhao == '-'){
$jieguo = $num1 - $num2;
}
else if($fuhao == '*'){
$jieguo = $num1 * $num2;
}
else if($fuhao == '/'){
$jieguo = $num1 / $num2;
}
}
else{
$jieguo = "";
$num1 = "";
$num2 = "";
$fuhao = "";
}
?>
<form action="" method="post">
<input type="text" name="data1" value="<?php echo $num1; ?>" />
<select name="yunsuanfu">
<option value="+" >+</option>
<option value="-" <?php if($fuhao=='-') echo 'selected="slected"'; ?> >-</option>
<option value="*" <?php if($fuhao=='*') echo 'selected="slected"'; ?> >*</option>
<option value="/" <?php if($fuhao=='/') echo 'selected="slected"'; ?> >/</option>
</select>
<input type="text" name="data2" value="<?php echo $num2; ?>" />
<input type="submit" value="=" />
<input type="text" name="result" value="<?php echo $jieguo; ?>" />
<!--<input type="text" name="result" value="<?php if(!empty($_POST)){echo $jieguo;} ?>" />
</form>
</body>
</html>
|
|