<form> <input type="text" name="num1"> <select name="fh"> <option value="jia">+</option> <option value="jian">-</option> <option value="chen" >*</option> <option value="chu">/</option> <option value="quzhi">%</option> </select> <input type="text" name="num2"> <input type="button" value="提交"> </form> <?php $num1=$_GET["num1"]; $num2=$_GET["num2"]; $a=$_GET['fh']; if(!is_numeric($num1)||!is_numeric($num2)){ echo "请输入数字"; } if($a=="jia"){ echo $num1.'+'.$num2.'='.($num1+$num2); } if($a=="jian"){ echo $num1.'-'.$num2.'='.($num1-$num2); } if($a=="chen"){ echo $num1.'*'.$num2.'='.($num1*$num2); } if($a=="chu"){ echo $num1.'/'.$num2.'='.($num1/$num2); } if($a=="quzhi"){ echo $num1.'%'.$num2.'='.($num1%$num2); } ?>
如题
寻觅 beyond2017-10-13 20:42:17
<form action='' method="get"> <input type="text" name="num1"> <select name="fh"> <option value="jia">+</option> <option value="jian">-</option> <option value="chen" >*</option> <option value="chu">/</option> <option value="quzhi">%</option> </select> <input type="text" name="num2"> <!-- <input type="button" value="提交"> --> <input type="submit" name="submit" value="提交"> </form> <?php if(isset($_GET['submit'])){ $num1=$_GET["num1"]; $num2=$_GET["num2"]; $a=$_GET['fh']; if(!is_numeric($num1)||!is_numeric($num2)){ echo "请输入数字"; } if($a=="jia"){ echo $num1.'+'.$num2.'='.($num1+$num2); } if($a=="jian"){ echo $num1.'-'.$num2.'='.($num1-$num2); } if($a=="chen"){ echo $num1.'*'.$num2.'='.($num1*$num2); } if($a=="chu"){ echo $num1.'/'.$num2.'='.($num1/$num2); } if($a=="quzhi"){ echo $num1.'%'.$num2.'='.($num1%$num2); } } ?>
代码我帮你改了一下,首先提交时类型为submit而不是用button,而且你的表单的action和method最好显式写出来,虽然不写是用get方式默认传到本页面;然后,php代码最好先判断是否接收到提交,如果不判断是否接收到提交,最开始会有警告