I have this form with which I am trying to take some user entered variables and pass them to calculate.php for counting and showing the result.
calculate.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>
calculate.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>
can anybody say where is my mistake as I get only the: The result of the calculation is:
Could just a mistype here, but – besides all that everyone else said, you forgot to close the
</form>tagI would also check for a POST request before processing: