-3

谁能给我一个创建一个简单函数的例子,它返回两个输入字段的总和?

<html>
  <body>
    number1:<input type="text" name="number1" />
    number2:<input type="text" name="number2" />
    <input type=submit name="submit" value="submit"/>
  </body>
</html>
4

4 回答 4

2

我认为这就是您要搜索的内容:http: //php.net/manual/en/tutorial.forms.php

于 2013-03-20T09:27:36.337 回答
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);
}
于 2013-03-20T09:31:34.803 回答
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>
于 2013-03-20T09:27:46.743 回答
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>
于 2013-03-20T09:31:36.113 回答