Credit Card Payment
connect_error){
echo "Unable to connect to the database server.
" . "
Error code " . mysql_errno() . ": " . mysql_error() . "
";
$errorCount++;
} else {
$sql = "UPDATE creditcard
SET balance=balance-'$amount', paymentDueDate=Now() + INTERVAL 30 DAY, paymentDate=Now()
WHERE creditid='$creditId'";
$result = queryMysql($sql);
$sql2 = "INSERT INTO transaction(username, accid, transtype, toID, acctype, amount)
SELECT username, NULL, 'Credit Card Payment', creditid, acctype, '$amount' FROM creditcard WHERE
username='$userName'";
$result = queryMysql($sql2);
// get new balance
$sql2 = "SELECT balance FROM creditcard WHERE creditid='$creditId'";
$result = queryMysql($sql2);
$row = $result->fetch_array(MYSQLI_ASSOC);
$newBalance = $row['balance'];
}
return $newBalance;
}
function displayForm() {
global $errorMessage;
echo $errorMessage;
?>
";
$showForm = FALSE;
}
else {
echo "User Name: ".$userName."
";
if (isset($_POST['Submit'])) {
$loanId = validateInput($_POST['loanId'],"Loan Id");
$amount = validateInput($_POST['amount'],"Payment Amount");
if($amount < 0) {
$errorMessage .= "Loan payment 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 {
// make payment in db
$newBalance = makeCreditPayment($userName, $loanId, $amount);
echo "Loan payment of $".$amount." has been received for Loan Id ".$loanId."
";
echo "New balance is $".$newBalance."
\n";
}
}
?>