However, everything seems to be working EXCEPT the result. So, just the most important part of the app. I've attached my input.php and output.php, as well as my functions.php.
If someone could tell me why its not giving me a value I'll personally send you a beer! :-P
Input.php:
<html>
<head>
<title>Input your Calculator Values</title>
<b>Input your Calculator Values</b>
</head>
<body>
<br>
<br>
<form name="calculate" action="output.php" method="post">
First Number:
<input type="text" name="var1" value="0" /><br>
Second Number:
<input type="text" name="var2" value="0" /><br>
<input type="submit" name="calculate" value="Add" />
<input type="submit" name="calculate" value="Subtract" />
<input type="submit" name="calculate" value="Multiply" />
<input type="submit" name="calculate" value="Divide" />
</form>
</body>
<?php
include ("navigation.php");
?>
</body>
</html>
Output.php:
<?php
require_once("functions.php");
?>
<html>
<head>
<title>Results of your Calculation</title>
<b>Results of your Calculation</b><br>
</head>
<body>
<?php
$var1 = $_POST[var1];
$var2 = $_POST[var2];
if ($_POST[calculate] == "Add") {
add($var1, $var2);
echo $value;
} elseif ($_POST[calculate] == "Subtract") {
subtract($var1, $var2);
echo $value;
} elseif ($_POST[calculate] == "Multiply") {
multiply($var1, $var2);
echo $value;
} elseif ($_POST[calculate] == "Divide") {
divide($var1, $var2);
echo $value;
} else {
echo "Something went terribly terribly wrong.";
}
echo "Your result: " . $value . "<br>";
?>
<?php
include ("navigation.php");
?>
</body>
</html>
Functions.php:
<?php
function add($var1, $var2) {
$value = $var1 + $var2;
return $value;
}
function subtract($var1, $var2) {
$value = $var1 - $var2;
return $value;
}
function divide($var1, $var2) {
$value = $var1 / $var2;
return $value;
}
function multiply($var1, $var2) {
$value = $var1 * $var2;
return $value;
}
?>
$value doesn't seem to be setting, and I'm not entirely sure why not.
Thanks again for your help. I feel like I'm the only one using this board.. so I apologize if you all get to know me pretty fast.. LOL!


Sign In
Create Account


Back to top









