Gossamer Forum
Home : General : Internet Technologies :

Php Calculation

Quote Reply
Php Calculation
I am creating a pgp loan calculation form and would like some help with the calculation part!

There are three fields. Loan amount, loan period and rate (%). I am pulling the rate in from a seperate page but would like to calculate a monthly amount that is due and an overall amount to repay, based on the users entries.

I think it should be fairly easy to do (for you guys!). My code thus far is as follows:-


<?php
if (file_exists("data.txt")) //does the file exist?
{
$FILE = fopen("data.txt","r"); // open data.txt for reading
$rate = fgets($FILE,4096); // read the file
fclose($FILE); // close file
}
else
{
$rate=1; // no file yes - default to rate of 1
}

//write the form ...
?>

<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
<strong><font size="2" face="Arial, Helvetica, sans-serif">Loan
Calculation form</font></strong><br>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td><strong><font size="2" face="Arial, Helvetica, sans-serif">Amount
:</font></strong></td>
<td><input name="amount" type="text" id="amount"></td>
</tr>
<tr>
<td><strong><font size="2" face="Arial, Helvetica, sans-serif">Period
:</font></strong> </td>
<td><input name="period" type="text" id="period"></td>
</tr>
<tr>
<td><strong><font size="2" face="Arial, Helvetica, sans-serif">Rate:</font></strong>
</td>
<td><input name="rate" type="text" id="rate" value="<?php echo $rate?>" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>

<br>
<input type="submit" name="Submit" value="Submit">
</form>

It is basically an empty form at the moment, but with the rate field populated with a value.
Quote Reply
Re: [steve55] Php Calculation In reply to
Is this related to Links SQL or a general PHP question?
Quote Reply
Re: [Paul] Php Calculation In reply to
Both really, I'm already populating the drop downs from a mysql database, but it is the php coding passing those values through to a results page that I'm stuck on....
Quote Reply
Re: [steve55] Php Calculation In reply to
Ok, I've put the thread in the Internet Tech forum whichg can be used for php related qn's.