• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

easy php code fix please!

Appledrop

Platinum Member
Uh huh, fixed, thanks guys


hi, new to php, am trying to make a very simple calculator, the user submits two numbers and an operator type (+,*,-, or /)... heres my code in calc.php (attached)

please see whats wrong.. the page is at

HERE IS THE PAGE!


<?php
$1st=$_POST["1st"];
$2nd=$_POST["2nd"];
$operator=$_POST["ope"];

function calculate($one,$two,$sign) { //start function
settype($one,'double');
settype($two,'double');

if(($sign=="/")) {
$total=($one/$two); }
else if(($sign=="*")) {
$total=($one*$two); }
else if(($sign=="+")) {
$total=($one+$two); }
else if(($sign=="-")) {
$total=($one-$two); }
else { $total=0;
echo "Wrong operator type!";
}
return $total; }
//end function
if((!empty==$ope)) {
echo "$1st $ope $2nd equals .";
echo calculate($1st,$2nd,$ope);
}
else { echo "an error occured"; }
?>


thanks
 
Back
Top