我有这个表格,我试图用它来获取一些用户输入的变量并将它们传递给 calculate.php 以计算和显示结果。
计算.html
<HTML>
<HEAD>
<TITLE>Calculation Form</TITLE>
</HEAD>
<BODY>
<FORM METHOD="POST" ACTION="calculate.php">
<P>Value 1: <INPUT TYPE="text" NAME="vall" SIZE=10></P>
<P>Value 2: <INPUT TYPE="text" NAME="val2" SIZE=10></P>
<P>Calculation:<br>
<INPUT TYPE="radio" NAME="calc" VALUE="add"> add<br>
<INPUT TYPE="radio" NAME="calc" VALUE="subtract"> subtract<br>
<INPUT TYPE="radio" NAME="calc" VALUE="multiply"> multiply<br>
<INPUT TYPE="radio" NAME="calc" VALUE="divide"> divide</P>
<P><INPUT TYPE="submit" NAME="submit" VALUE="Calculate"></P>
</BODY>
</HTML>
计算.php:
<?
if (($_POST["vall"] == "") || ($_POST["val2"] == "") || ($_POST["calc"] =="")) {
header("Location: http://localhost/calculate.html");
exit;
}
if ($_POST["calc"] == "add") {
$result = $_POST["vall"] + $_POST["val2"];
} else if ($_POST["calc"] == "subtract") {
$result = $_POST["vall"] - $_POST["val2"];
} else if ($_POST["calc"] == "multiply") {
$result = $_POST["vall"] * $_POST["val2"];
} else if ($_POST["calc"] == "divide") {
$result = $_POST["vall"] / $_POST["val2"];
}
?>
<HTML>
<HEAD>
<TITLE>Calculation Result</TITLE>
</HEAD>
<BODY>
<P>The result of the calculation is: <? echo $result; ?></P>
</BODY>
</HTML>
谁能说我的错误在哪里,因为我只得到: 计算的结果是: