Home  >  Article  >  Backend Development  >  PHP 计算器解决办法

PHP 计算器解决办法

WBOY
WBOYOriginal
2016-06-13 12:53:46823browse

PHP 计算器
php做的一个计算器为什么只要一点计算,页面刷新了,但是第一个文本框的值还是没变,而第二个文文本框的值就没了,这种情况是不是默认的。。下面是我的代码?求真相??nbsp;html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">








$mess = "";

if(isset($_POST["sub"])){

if($_POST["num1"]==""){
$mess.="第一个数不能为空!
";
}else{
if(!is_numeric($_POST["num1"])){
$mess.="第一个数必须是数字!
";
}

}
if(is_numeric($_POST["num1"])){
if($_POST["num2"]==""){
$mess.="第二个数不能为空!
";
}else{
if(!is_numeric($_POST["num2"])){
$mess.="第二个数必须是数字!
";
}else{
if($_POST["opt"]=="/" && $_POST["num2"]==0){
$mess.="除数不能为0" ;
}

}
}
}


}

?>
















if(isset($_POST["sub"])){
echo '';
}


?>



计算器

" size="5" />


';
if(!$mess){
$sum = 0;
switch($_POST["opt"]){
case "+";
$sum = $_POST["num1"] + $_POST["num2"]; break;
case "-";
$sum = $_POST["num1"] - $_POST["num2"]; break;
case "*";
$sum = $_POST["num1"] * $_POST["num2"]; break;
case "/";
$sum = $_POST["num1"] / $_POST["num2"]; break;
case "%";
$sum = $_POST["num1"] % $_POST["num2"]; break;
}

echo "结果:{$_POST['num1']} {$_POST['opt']} {$_POST['num2']} = {$sum}";

}else{
echo $mess;
}

echo '








没什么分,谢谢!!!!
input
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn