有人能给我一个创建一个简单函数的例子,它返回两个输入字段的总和吗?
<html>
<body>
number1:<input type="text" name="number1" />
number2:<input type="text" name="number2" />
<input type=submit name="submit" value="submit"/>
</body>
</html>
答案 0 :(得分:2)
我认为这就是您要搜索的内容: http://php.net/manual/en/tutorial.forms.php
答案 1 :(得分:1)
function addition( $num1,$num2)
{
echo "Result = " . $num1 + $num2;
}
and call the function by
if(isset($_POST["submit"]))
{
$num1=$_POST['number1'];
$num2=$_POST['number2'];
addition( $num1,$num2);
}
答案 2 :(得分:0)
尝试以下方法:
<?php
if(isset($_POST))
{
echo "Result = " . $_POST['number1'] + $_POST['number2'];
}
?>
<html>
<head>
<title> Example of the radio blur method</title>
</head>
<body>
<form name="form1">
<input type="text" name="number1" value="">
<input type="text" name="number2" value="">
<input type="submit" name="submit" value="Add">
</form>
</body>
</html>
答案 3 :(得分:0)
尝试;
<html>
<body>
<form action='<?php echo $_SERVER["PHP_SELF"] ?>' method='post'>
number1:<input type='text' name='number1'/>
number2:<input type='text' name='number2'/>
<input type='submit' name='submit' value='submit'/>
</form>
<br/>
<?php
if($_POST["submit"]){
echo "$_POST[number1] + $_POST[number2] = ".($_POST["number1"] + $_POST["number2"])."<br/>\n";
}
?>
</body>
</html>