Thread: php not working
View Single Post
Old 29-10-2006, 15:23   #1 (permalink)
2Dfruit
Biscuit
 
2Dfruit's Avatar
 
Join Date: Jun 2006
Location: Ireland
Posts: 1,073
php not working

i have a mortgage calculator from site but can't get it to work. any ideas.
I've set the permissons to 755 on all files and the folder.

here's the table with some code:

Code:
<? /* TigerTom's Loan & Mortgage Calculator (TTLoanCalc) http://www.tigertom.com http://www.ttfreeware.com Copyright (c) 2005 T. O' Donnell Developed for TigerTom by Jon K. Released under the GNU General Public License, with the following proviso: That the HTML of hyperlinks to the authors' websites this software generates shall remain intact and unaltered, in any version of this software you make. If this is not strictly adhered to, your licence shall be rendered null, void and invalid. */ // Remove bad input $year = eregi_replace ("\)|\(|src|\[|\]|script|<|>|\"|\'|;|&", "", $year); $downpayment_percent = eregi_replace ("\)|\(|src|\[|\]|script|<|>|\"|\'|;|&", "", $downpayment_percent); $loan = eregi_replace ("\)|\(|src|\[|\]|script|<|>|\"|\'|;|&", "", $loan); $interest_rate = eregi_replace ("\)|\(|src|\[|\]|script|<|>|\"|\'|;|&", "", $interest_rate); $s = $currency; // Show form only if there is no action if ($action!="Calculate") { print "<html>\n"; print "<head><TITLE>Mortgage Calculator</TITLE>\n"; print "<link href=loan.css rel=stylesheet type=text/css />\n"; print "</head>\n"; print "<form>\n"; print "<table cellpadding=2 width=300 border=0 ALIGN=center>\n"; print "<tr align=center><td colspan=2><b>Mortgage Information</b></td></tr>\n"; print "<tr>\n"; print "<td class=flabel>Sale Price of Home</td>\n"; print "<td class=finput><input type=text name=loan size=7></td>\n"; print "</tr>\n"; print "<tr>\n"; print "<td class=flabel>Percentage Down, %</td>\n"; print "<td class=finput><input type=text name=downpayment_percent size=7></td>\n"; print "</tr>\n"; print "<tr>\n"; print "<td class=flabel>Length of mortgage, years</td>\n"; print "<td class=finput><input type=text name=year size=7></td>\n"; print "</tr>\n"; print "<tr>\n"; print "<td class=flabel>Interest rate, %</td>\n"; print "<td class=finput><input type=text name=interest_rate size=4></td>\n"; print "</tr>\n"; print "<tr>\n"; print "<td class=flabel>Currency</td>\n"; print "<td class=finput>\n"; print "<select name=currency>\n"; print "<option value=$>$</option>\n"; print "<option value=&euro;>&euro;</option>\n"; print "<option value=&pound;>&pound;</option>\n"; print "</td>\n"; print "</tr>\n"; print "<tr>\n"; print "<td class=flabel>Show amortization</td>\n"; print "<td class=finput><input type=checkbox name=amortization></td>\n"; print "</tr>\n"; print "<input type=hidden name=periodicity value=12>\n"; print "<tr><td colspan=2 align=center><input type=submit value=Calculate name=action></td></tr>\n"; print "</table>\n"; print "</html>\n"; print "</form>\n"; print "<center>"; footer(); print "</center>"; exit; } // Only perform calculation and show tables if user // click calculate button include "math.php"; ?> <html> <head> <link href="loan.css" rel="stylesheet" type="text/css" /> </head> <table cellpadding="2" cellspacing="0" border="0" width="100%"> <tr> <td colspan=2 class=header>Mortgage Payment Report</td> </tr> <tr class=top> <td align="right">Down Payment:</td> <td><b> <? print $s.$downpayment; ?> </b></td> </tr> <tr class=top> <td align="right">Amount Financed:</td> <td><b> <? print $s.$loan; ?> </b></td> </tr> <tr class=top> <td align="right">Length:</td> <td><b> <? print "$year years"; ?> </b></td> </tr> <tr class=top> <td align="right">Annual interest:</td> <td><b> <? print $interest_rate; ?> % </b></td> </tr> <tr class=toptotal> <td align="right">Monthly Payment:</td> <td><b> <? print $s.$periodic_payment; ?> </b><br>(excluding tax and insurance)</td> </tr> </table> <!-- This is the Totals table --!> <table cellpadding="5" cellspacing="0" border="1" width="100%"> <tr class=total1> <td colspan="4">Totals</td> </tr> <tr class=total2> <td>&nbsp;</td> <td colspan="3"> Outgoings: <B><? print $s.$total_paid; ?></B> paid out.<br> <? print $s.$total_interest; ?> paid in <b>interest</b>.<br> <? print $s.$loan; ?> paid towards <b>principal</b>.<br> </td> </tr> <!-- This is the Amortization table --!> <? if (!$amortization) { footer(); exit; } ?> <tr class=aheader> <td colspan="4">Amortization</td> </tr> <tr class=aheader align=right> <td>Month</td> <td>Interest Paid</td> <td>Principal Paid</td> <td>Balance Outstanding</td> </tr> <? $yr = 0; for ($i=0; $i<$year*12; $i++) { print "<tr class=acontent>\n"; print "<td>".(($i%12)+1)."</td>\n"; print "<td>$s$periodic_interest[$i]</td>\n"; print "<td>$s$periodic_principal[$i]</td>\n"; print "<td>$s$balance[$i]</td>\n"; print "</tr>\n"; if ($i%12==11) { $ytotal = $yinterest[$yr] + $yprincipal[$yr]; print "<tr class=total1>\n"; print "<td colspan=4>Totals for year ".($yr+1)."</td>\n"; print "</tr>\n"; print "<tr class=total2>\n"; print "<td>&nbsp;</td>\n"; print "<td colspan=3>\n"; print "Outgoings: <B>$s$ytotal</B> paid out in year ".($yr+1).".<br>\n"; print "$s$yinterest[$yr] paid in <b>interest</b>.<br>\n"; print "$s$yprincipal[$yr] paid towards <b>principal</b>.<br>\n"; print "</td>\n"; print "</tr>\n"; if ($yr != $year-1) { print "<tr class=aheader align=right>\n"; print "<td>Month</td>\n"; print "<td>Interest Paid</td>\n"; print "<td>Principal Paid</td>\n"; print "<td>Balance Outstanding</td>\n"; print "</tr>\n"; } $yr++; } } footer(); function footer() { print "<BR><BR><tr class=total2><td colspan=4 align=center>\n"; print "<!--// Altering the following HTML code in any way invalidates your licence to use this software --><FONT SIZE=\"1\"><a href=\"http://www.ttfreeware.com\">TTLoanCalc</a> by Jon K. for <a href=\"http://www.tigertom.com\">TigerTom</a></FONT>\n"; print "</td></tr>\n"; } ?>

here's the math.php include

Code:
<? /* TigerTom's Loan & Mortgage Calculator (TTLoanCalc) Version 1.1 http://www.tigertom.com http://www.ttfreeware.com Copyright (c) 2005 T. O' Donnell Developed for TigerTom by Jon K. Released under the GNU General Public License, with the following proviso: That the HTML of hyperlinks to the authors' websites this software generates shall remain intact and unaltered, in any version of this software you make. If this is not strictly adhered to, your licence shall be rendered null, void and invalid. */ $downpayment = $downpayment_percent / 100 * $loan; $downpayment = number_format($downpayment, 2, '.', ''); $interest_rate = number_format($interest_rate, 2, '.', ''); $loan = (1-$downpayment_percent/100)*$loan; $loan = number_format($loan, 2, '.', ''); $periodic_payment = ($loan*$interest_rate/100)/($periodicity*(1-pow(1+($interest_rate/100)/$periodicity, -$year*$periodicity))); // $periodic_payment = $loan * (($interest/12) / (1-pow((1+$interest/12), (-$year*12)))); $total_paid = $periodic_payment * $year * $periodicity; $total_interest = $total_paid - $loan; $amount_left = $loan; $year_interest = $year_principal = 0; $periodic_interest = array(); $periodic_principal = array(); $balance = array(); $yinterest = array(); $yprincipal = array(); $j = 0; for ($i=0; $i<$year*$periodicity; $i++) { $periodic_interest[$i] = $amount_left * ($interest_rate/100) / $periodicity; $periodic_principal[$i] = $periodic_payment - $periodic_interest[$i]; $amount_left -= $periodic_principal[$i]; $balance[$i] = $amount_left; // print "[$i] $periodic_interest[$i]\t$periodic_principal[$i]\t$balance[$i]\n"; $year_interest += $periodic_interest[$i]; $year_principal += $periodic_principal[$i]; $periodic_interest[$i] = number_format($periodic_interest[$i], 2, '.', ''); $periodic_principal[$i] = number_format($periodic_principal[$i], 2, '.', ''); $amount_left = $amount_left < 0 ? 0 : $amount_left; $balance[$i]= number_format($amount_left, 2, '.', ''); // if ($i%$periodicity==($periodicity-1)) { if (!(($i+1) % $periodicity)) { $yinterest[$j] = number_format($year_interest, 2, '.', ''); $yprincipal[$j] = number_format($year_principal, 2, '.', ''); $j++; $year_interest = $year_principal = 0; } } $periodic_payment = number_format($periodic_payment, 2, '.', ''); $total_paid = number_format($total_paid, 2, '.', ''); $total_interest = number_format($total_interest, 2, '.', ''); ?>
  Reply With Quote