当前位置:编程学习 > php >>

一个php计算器程序 寻错

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns=" http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><html> <head> <title> 计算器</title></head><body> <?php if(isset($_POST["number1"])&&isset($_POST["number2"])) { if(empty($_POST["$number1"])&&empty($_POST["number2"])) { echo"操作数不能为空"; unset($_POST["sub"]); } else { $number1=$_GET["number1"]; $number2=$_GET["number2"]; $oper=$_GET["oper"]; } } ?> <?php if(isset($_GET["sub"])){ $sum=0; switch($oper){ case"+": $sum=$_GET["number1"]+$_GET["number2"]; break; case"-": $sum=$_GET["number1"]-$_GET["number2"]; break; case"x": $sum=$_GET["number1"]*$_GET["number2"]; break; case"/": if($numebr2=="0") echo"0不能为除数"; else $sum=$_GET["number1"]/$_GET["number2"]; break; } }
 ?>
  <center><h1>计算器</h1> <table border='1'><tr><td><form action="" method="get"> <input type="text" name="number1" value="<?php                                                                                              if(!empty($number1))  echo $number1;  ?>"></td><td>  <select name="oper">   <option value ="+">+</option>    <option value ="-">-</option> <option value ="*">*</option>  <option value ="\">\</option>  </select></td>  <td> <input type="text" name="number2"value="<?php                                                                                              if(!empty($number2))  echo $number2;  ?>"></td>  <td><input name="sub" type="submit" value="计算" /></td></tr>  </center>

  <?php       if(isset($_GET["sub"])){       echo '<tr><td colspan="4">';   echo  "结果:".$_GET["number1"]." ".$_GET["oper"]." ".$_GET["number2"]."=".$sum;   echo '</td></tr>';    }  ?></form> </table> </body></html>
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,