I have a webpage which calculates loan repayments based on variables supplied by a user form. I also have a database which sits behind the form storing each loans variables. I have a working version of the webpage which can store the data and calculate the loan’s details ??" but only as a two click two step operation. However, I would like to get the webpage to submit the data to the database, and calculate the loan details with a single button push.
## Deliverables
*****irrelevant code before this line *****
<tr><td><CENTER> <H1>Loan Amortisation Calculator</H1></CENTER>
<HR>
<CENTER>
<?php if (isset($_GET['addprovidername'])); ?>
<CENTER>To calculate your monthly the details of your loan and
click the calculate button below.
If you would also like to help us identify the best loans - please tell us a bit
about your loan and click the survey button
?
? </CENTER>
<form name=form1 action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<label> Type your loan provider here:<br/></label>
<INPUT name=providername value=" ">
<br/>
<input type="submit" value="Optional Survey SUBMIT" />
<FORM name=form2>
<P>
<TABLE border=3>
? <TBODY>
? <TR>
? ? ? <TD>Amount of the loan ($)</TD>
? ? ? <TD><INPUT name=principle value="10000"></TD></TR>
? <TR>
? ? ? <TD>Annual interest rate (%)</TD>
? ? ? <TD><INPUT name=apr value="7.5"></TD></TR>
? <TR>
? ? ? <TD>Total number of years</TD>
? ? ? <TD><INPUT name=years value="10"></TD></TR>
<INPUT onclick=compute([login to view URL]) type=button value=Calculate>
? </TBODY></TABLE></FORM></CENTER>
</form>
? ? ? ?
? ? ?
<td><tr></table>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
? <?php
$link = @mysql_connect('localhost','root','password');
if (!link) {
('<p> Unable to connect to the ' .
? ? 'database server at this time.</p>' );
? ? exit();
}
//$dbcnx = @mysql_connect('[login to view URL]', 'root', 'password');
//if (!$dbcnx) {
//? exit ('<p>Unable to connect to the ' .
//? 'database server at this time.</p>');
//}
//Select the database
if (<!@mysql_select_db('amort'>)) {
exit ('<p> Unable to locate the amort ' . 'database at this time.</p>');
}
if (isset($_POST['providername'])) {
? $providername= $_POST['providername'];
? $sql = "INSERT INTO amort SET
? providername='$providername',
? loandate=CURDATE()";
if (@mysql_query($sql)) {
? echo '<p>Your loan has been added.</p>';
? } else {
? echo '<p>Error adding submitted loan: ' .
? mysql_error() . '</p>';
}
}
$result = @mysql_query('SELECT providername FROM amort');
if (!$result) {
? exit ('<p>Error performing query: ' . mysql_error() . '</p>');
}
while ($row = mysql_fetch_array($result)) {
? echo '<p>' . $row['providername'] . '</P>';
}
echo '<p><a href="' . $_SERVER['PHP_SELF'] .
? '?addprovidername=1">Add another loan!</a></p>';
?
mysql_close($link); ?>
<script language="JavaScript">
function BrowserCheck(msg) {
if ([login to view URL] !="Microsoft Internet Explorer"){
alert("Please use Internet Explorer to view this page");
msg="Your Browser does not understand VBScript";
,alert(msg)
}
}
</script>