<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); } ?>
Like the title
ringa_lee2017-10-14 09:26:46
Yes, button is just a button attribute and does not have the function of submitting the form. Unless ajax is used to submit, button will be used~
寻觅 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); } } ?>
I changed the code for you. First, the type of submission is submit instead of button. It is best to write the action and method of your form explicitly. Even if you do not write it, it will be transmitted to this page by default using the get method. ;Then, it is best for the PHP code to first determine whether a submission has been received. If it does not determine whether a submission has been received, there will be a warning at the beginning