Home > Backend Development > PHP Tutorial > 这一段程序毛病在哪儿

这一段程序毛病在哪儿

WBOY
Release: 2016-06-13 10:36:29
Original
824 people have browsed it

这一段程序毛病在哪里
//这是一段计算器的代码
//接受用户从mycal.php输入的数据
$num1=$_REQUEST['num1'];
$num2=$_REQUEST['num2'];
$oper=$_REQUEST['oper'];//$_REQUEST方法可以接受用户的post或者get请求的数据
$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 "运算符不准确";
  } 
 echo "运算结果是:".$res;
?>

结果不论输入什么数字和运算符,结果都是“运算符不准确运算结果是:0”

------解决方案--------------------
Miss $

//接受用户从mycal.php输入的数据
$num1=$_REQUEST['num1'];
$num2=$_REQUEST['num2'];
$oper=$_REQUEST['oper'];//$_REQUEST方法可以接受用户的post或者get请求的数据
$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 "运算符不准确";
}
 echo "运算结果是:".$res;
------解决方案--------------------
switch ($oper){
------解决方案--------------------
楼上都是正解。。
------解决方案--------------------

探讨
//这是一段计算器的代码
//接受用户从mycal.php输入的数据
$num1=$_REQUEST['num1'];
$num2=$_REQUEST['num2'];
$oper=$_REQUEST['oper'];//$_REQUEST方法可以接受用户的post或者get请求的数据
$res=0;
switch (oper){
case"+":$res=$num1+……

------解决方案--------------------
++
探讨

Miss $

//接受用户从mycal.php输入的数据
$num1=$_REQUEST['num1'];
$num2=$_REQUEST['num2'];
$oper=$_REQUEST['oper'];//$_REQUEST方法可以接受用户的post或者get请求的数据
$res=0;
switch ($oper){
case"+":$res=$num1+$num2;
……
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template