Simple PHP Calculator - Submit Button

I’m a newbie having an issue. When I click the “Calculate” button, it does the first calculation and not all calculations. If I click a second time then it will do it. What do I need to do in order to get all calculations performed in just one click?

<?php if(!IsSet($_POST['Submit']) || $_POST['Submit'] !="Calculate"){ $_POST['nla']= ""; $_POST['cpb']= ""; $_POST['total']= ""; $_POST['bmt']= ""; $_POST['lmt']= ""; $ErrorMessage=""; } else do { $_POST['start']=1; //Code executed on second and subsequent entries to this routine $ErrorMessage=""; $aa = (double) $_POST['nla']; if($aa <= 0.0 ){ $ErrorMessage="Please re-enter New Loan Amount"; break; } $bb = (double) $_POST['cpb']; if($bb <= 0.0 ){ $ErrorMessage="Please re-enter Current Principal Balance"; break; } //Now do the payment calculations secure in the knowledge that we have legit inputs $_POST['total']= (string) round(($aa - $bb), 2); $_POST['bmt']= (string) round(($total * .018), 2); $_POST['lmt']= (string) round(($total * .0025), 2); $_POST['start']=2; }while($_POST['start'] == 1); ?>

Thank you,
Jeff

I think I figured it out. I added/changed the following:

$total2 = ($aa - $bb);

$_POST[‘total’]= (string) round(($aa - $bb), 2);
$_POST[‘bmt’]= (string) round(($total2 * .018), 2);
$_POST[‘lmt’]= (string) round(($total2 * .0025), 2);

Sponsor our Newsletter | Privacy Policy | Terms of Service