dquigley
New Member
- Messages
- 249
- Reaction score
- 0
- Points
- 0
I am creating a script from a book that is teaching me php and I am having an issue with this calculator script, it apears to be working but if I click submit I get the error
Sorry, nevermind after looking at my post for a minute I found the error
Ill post it in case any of you are trying to learn too or are curious.
Heres the error from the first html script
Heres how I fixed it
The first html script isForbidden
You don't have permission to access /calculate.php" on this server.
And the second script the php part is<HTML>
<HEAD>
<TITLE>Calculation Form</TITLE>
</HEAD>
<BODY>
<FORM METHOD="post" ACTION=calculate.php">
<P>Value 1: <INPUT TYPE="text" NAME="va11" SIZE=10></P>
<P>Value 2: <INPUT TYPE="text" NAME="va12" 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>
</FORM>
</BODY>
</HTML>
Edit:<?
if (($_POST[va11] =="") || ($_POST[va12] =="") || ($_POST[calc] =="")) {
header ("Location: calculate_form.html");
exit;
}
if ($_POST[calc] == "add") {
$result = $_POST[va11] + $_POST[va12];
} else if ($_POST[calc] == "subtract") {
$result = $_POST[va11] - $_POST[va12];
} else if ($_POST[calc] == "multiply") {
$result = $_POST[va11] * $_POST[va12];
} else if ($_POST[calc] == "divide") {
$result = $_POST[va11] / $_POST[va12];
}
?>
<HTML>
<HEAD>
<TITLE>Calculation Result</TITLE>
</HEAD>
<BODY>
<P>The result of the calculation is: <? echo "$result"; ?></P>
</BODY>
</HTML>
Sorry, nevermind after looking at my post for a minute I found the error
Ill post it in case any of you are trying to learn too or are curious.
Heres the error from the first html script
<FORM METHOD="post" ACTION=calculate.php">
Heres how I fixed it
<FORM METHOD="post" ACTION="calculate.php">
Last edited: