Why does nothing happen when I enter a number to submit?
益伦
益伦 2017-10-13 16:09:35
0
2
1440
<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

益伦
益伦

reply all(2)
ringa_lee

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~

寻觅 beyond
<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

  • reply It turns out that it is the difference between submit and button. The form is lazy and I will write it all in the future.
    益伦 author 2017-10-13 20:51:54
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template