Okay, I've rubber-ducked this enough, time to ask for help.
I'm new to PHP, I'm trying to do some math with values provided in an HTML form and one of my functions isn't working. The funny part is another function written in basically identical way is working just fine.
Here's my PHP code:
//For passing values around
$area = 50;
$plants = 0;
$pi = 3.14;
//Calculate the area
function calcsquare($len, $wid) {
$a = (double) $len * (double) $wid;
return $a;
}
function calccirc($rad, $pi) {
$a = (double) $rad * (double) $pi;
return $a;
}
//Make the buttons do stuff
if($_SERVER['REQUEST_METHOD'] == "POST" and isset($_POST['calcarea_button']))
{
if($POST["radius"] == "") {
$area = calcsquare((double) $_POST["length"], (double) $_POST["width"]);
} else {
//$area = calccirc((double) $_POST["radius"], (double) $pi);
//$area = $_POST["radius"];
//$area = 3.14;
$area = "Seriously wtf.";
}
}
(I know I haven't added any error handling. That is a problem for Future Me.)
And here's the relevant HTML:
<div class="calcarea">
<!--Calculate the area-->
<form action="calc_plants.php" method="post">
Length: <input name="length" type="text" /> ft.<br>
Width: <input name="width" type="text" /> ft.<br>
Radius: <input name="radius" type="text" /> ft.</br>
<input type="submit" value="Calculate" name="calcarea_button">
</form>
</div>
And $area is returned by this code elsewhere on the page:
<?php echo $area; ?> sq. ft.<br>
The bit where $area is filled by calcsquare works exactly how I intended, but no matter what I do, the else case returns 0. (I've set it to 50 initially as a troubleshooting measure, so I know it's being changed to 0 rather than not being changed at all.) The function calccirc is what I'm actually trying to accomplish, but you can see all the commented-out stuff I was using to try to make $area say something other than 0. I have no idea where that's even coming from. Again, calcsquare works fine every time I try it, so I know it ought to work!
Again, very new to PHP, please be gentle. Explain it like you would to your mom.