谁能给我一个创建一个简单函数的例子,它返回两个输入字段的总和?
<html>
<body>
number1:<input type="text" name="number1" />
number2:<input type="text" name="number2" />
<input type=submit name="submit" value="submit"/>
</body>
</html>
我认为这就是您要搜索的内容:http: //php.net/manual/en/tutorial.forms.php
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);
}
尝试以下操作:
<?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>
尝试;
<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>