New Loan

connect_error){ echo "

Unable to connect to the database server.

" . "

Error code " . mysql_errno() . ": " . mysql_error() . "

"; $errorCount++; } else { $sql = "INSERT INTO loan (username, amount, balance, interestrate, dateopened, paymentDueDate) VALUES ('$userName', '$balance', '$balance', .1050, Now(), Now() + INTERVAL 30 DAY)"; $result = queryMysql($sql); //get loan id and insert into transaction table $sql = "SELECT max(loanid) FROM loan WHERE username='$userName'"; $result = queryMysql($sql); $row = $result->fetch_array(MYSQLI_ASSOC); $loanid = $row['max(loanid)']; $sql2 = "INSERT INTO transaction(username,transtype, toID, acctype, amount) SELECT username, 'New Loan', '$loanid', 'Loan', '$balance' FROM loan WHERE username='$userName'"; $result = queryMysql($sql2); /* // get loan id $SQLstring2 = "SELECT max(loanid) as loanId FROM loan;"; $QueryResult2 = @mysql_query($SQLstring2, $db_connect); $row = mysql_fetch_assoc($QueryResult2); $loanId = $row['loanId']; * */ } return $loanid; } function displayForm() { global $errorMessage; echo $errorMessage; ?>

Loan Amount:




"; $showForm = FALSE; } else { echo "User Name: ".$userName."
"; if (isset($_POST['Submit'])) { $balance = validateInput($_POST['balance'],"Loan Amount"); if($balance < 0) { $errorMessage .= "Loan amount must be a positive number.
"; $errorCount++; } if ($errorCount == 0) $showForm = FALSE; else $showForm = TRUE; } if ($showForm == TRUE) { if ($errorCount > 0) // if there were errors $errorMessage .= "

Please re-enter the form information below.

\n"; displayForm (); } else { // create loan in db $loanId = openNewLoan($userName,$balance); echo "

New loan has been created for ".$userName." with Loan Id ".$loanId." for ".$balance."



\n"; } } ?>