new_loan.php under construction

This commit is contained in:
ry1015
2014-11-24 22:52:07 -08:00
parent 1580710b53
commit 61823305bc
7 changed files with 64 additions and 126 deletions

View File

@@ -20,7 +20,6 @@ function deposit($userName,$accountId,$amount) {
global $errorCount; global $errorCount;
global $errorMessage; global $errorMessage;
global $connection; global $connection;
//include 'includes/inc_dbConnect.php';
// Select database. // Select database.
if ($connection->connect_error) if ($connection->connect_error)
@@ -36,6 +35,12 @@ function deposit($userName,$accountId,$amount) {
// record login to login_history table // record login to login_history table
$sql2 = "UPDATE account SET balance=balance+'$amount' WHERE username='$userName' and accID='$accountId'"; $sql2 = "UPDATE account SET balance=balance+'$amount' WHERE username='$userName' and accID='$accountId'";
$result = queryMysql($sql2); $result = queryMysql($sql2);
$sql2 = "INSERT INTO transaction(username, transtype, toID, acctype, amount)
SELECT username, 'Deposit', accID, acctype, '$amount' FROM account WHERE
accID='$accountId'";
$result = queryMysql($sql2);
$errorMessage .= "<p>Deposit completed.</p>"; $errorMessage .= "<p>Deposit completed.</p>";
} }
else { else {
@@ -43,38 +48,6 @@ function deposit($userName,$accountId,$amount) {
$errorMessage .= "Invalid user name/account number.<br />"; $errorMessage .= "Invalid user name/account number.<br />";
} }
} }
/*
if ($db_connect === FALSE) {
$errorMessage .= "<p>Unable to connect to the database server.</p>" . "<p>Error code " . mysql_errno() . ": " . mysql_error() . "</p>";
$errorCount++;
}
else {
if (!@mysql_select_db($db_name, $db_connect)) {
$errorMessage .= "<p>Connection error. Please try again later.</p>";
$errorCount++;
}
else {
// verify the account belongs to the user
$sql = "SELECT * FROM account WHERE username='$userName' and accountid='$accountId'";
$result = mysql_query($sql);
// If result matched $myusername and $mypassword, table row must be 1 row
$count = mysql_num_rows($result);
if($count == 1){
// record login to login_history table
$sql2 = "UPDATE account SET balance=balance+'$amount' WHERE username='$userName' and accountid='$accountId'";
$result = mysql_query($sql2);
$errorMessage .= "<p>Deposit completed.</p>";
}
else {
$errorCount++;
$errorMessage .= "Invalid user name/account number.<br />";
}
}
mysql_close($db_connect);
}
*
*/
} }
function displayForm() { function displayForm() {

View File

@@ -15,7 +15,10 @@ function createTable($name, $query){
function queryMysql($query){ function queryMysql($query){
global $connection; global $connection;
$result = $connection->query($query); $result = $connection->query($query);
if (!$result) die ($connection->error); if (!$result) {
echo $query;
die ($connection->error);
}
return $result; return $result;
} }

View File

@@ -33,46 +33,6 @@ function showAccounts($userName) {
} }
$result->close(); $result->close();
} }
/*
if ($db_connect === FALSE)
echo "<p>Unable to connect to the database server.</p>" . "<p>Error code " . mysql_errno() . ": " . mysql_error() . "</p>";
else {
if (!@mysql_select_db($db_name, $db_connect))
echo "<p>Connection error. Please try again later.</p>";
else {
*
*
$SQLstring = "SELECT * from account
WHERE username='$userName'";
*
$QueryResult = @mysql_query($SQLstring, $db_connect);
if (mysql_num_rows($QueryResult) == 0)
echo "<p>You have no accounts open.</p>";
else {
echo "<table width='50%' border='1'>";
echo "<tr>
<th>Account Type</th>
<th>Account Number</th>
<th>Balance</th>
</tr>";
*
*
while (($Row = mysql_fetch_assoc($QueryResult)) !== FALSE)
{
echo "<td>{$Row['accounttype']}</td>";
echo "<td>{$Row['accountid']}</td>";
echo "<td>{$Row['balance']}</td></tr>";
}
echo "</table><br /><br />";
}
}
mysql_close($db_connect);
}
*
*/
//return ($retval);
} }
$userName = ""; $userName = "";

View File

@@ -1,5 +1,3 @@
<?php
session_start(); ?>
<!-- F8L Exception Online Bank | New Loan --> <!-- F8L Exception Online Bank | New Loan -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
@@ -9,40 +7,43 @@ session_start(); ?>
<title>F8L Exception Online Bank | New Loan</title> <title>F8L Exception Online Bank | New Loan</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<?php include 'includes/inc_header.php'; ?> <?php include 'includes/inc_header.php'; ?>
<h1>New Loan</h1><hr />
</head> </head>
<body> <body>
<hr />
<h1>New Loan</h1>
<?php <?php
include 'includes/inc_validateInput.php'; include 'includes/inc_validateInput.php';
include 'functions.php';
function openNewLoan($userName,$balance) { function openNewLoan($userName,$balance) {
global $errorCount; global $errorCount;
global $errorMessage; global $errorMessage;
include 'includes/inc_dbConnect.php'; global $connection;
// Select database. // Select database.
if ($db_connect === FALSE) if ($connection->connect_error){
echo "<p>Unable to connect to the database server.</p>" . "<p>Error code " . mysql_errno() . ": " . mysql_error() . "</p>"; echo "<p>Unable to connect to the database server.</p>" . "<p>Error code " . mysql_errno() . ": " . mysql_error() . "</p>";
$errorCount++;
else { } else {
if (!@mysql_select_db($db_name, $db_connect))
echo "<p>Connection error. Please try again later.</p>"; if (!@mysql_select_db($db_name, $db_connect))
else { echo "<p>Connection error. Please try again later.</p>";
$today = date("Ymd"); else {
$dueDate = date('Y-m-d', strtotime("+30 days")); // set due date to 30 days after today $today = date("Ymd");
$SQLstring = "INSERT INTO $dueDate = date('Y-m-d', strtotime("+30 days")); // set due date to 30 days after today
loan (username, amount, balance, dateOpened, paymentDueDate) $SQLstring = "INSERT INTO
VALUES ('$userName', '$balance', '$balance', '$today', '$dueDate')"; loan (username, amount, balance, dateOpened, paymentDueDate)
$QueryResult = @mysql_query($SQLstring, $db_connect); VALUES ('$userName', '$balance', '$balance', '$today', '$dueDate')";
$QueryResult = @mysql_query($SQLstring, $db_connect);
// get loan id
$SQLstring2 = "SELECT max(loanid) as loanId FROM loan;"; // get loan id
$QueryResult2 = @mysql_query($SQLstring2, $db_connect); $SQLstring2 = "SELECT max(loanid) as loanId FROM loan;";
$row = mysql_fetch_assoc($QueryResult2); $QueryResult2 = @mysql_query($SQLstring2, $db_connect);
$loanId = $row['loanId']; $row = mysql_fetch_assoc($QueryResult2);
} $loanId = $row['loanId'];
mysql_close($db_connect); }
mysql_close($db_connect);
} }
return $loanId; return $loanId;
} }
@@ -100,7 +101,6 @@ else {
echo "<p>New loan has been created for ".$userName." with Loan Id ".$loanId." for ".$balance."</p><br /><br />\n"; echo "<p>New loan has been created for ".$userName." with Loan Id ".$loanId." for ".$balance."</p><br /><br />\n";
} }
} }
include 'includes/inc_text_menu.php';
?> ?>
</body> </body>

9
f8l_exception/test.php Normal file
View File

@@ -0,0 +1,9 @@
<?php
include 'functions.php';
$accountId = 106;
$type = "SELECT acctype FROM account where '$accountId'=accID";
$result2 = queryMysql($type);
$row = $result2->fetch_array(MYSQLI_ASSOC);
echo $row['acctype'];
?>

View File

@@ -39,6 +39,17 @@ function transfer($userName,$fromAccountId,$toAccountId,$amount) {
$result = queryMysql($sql2); $result = queryMysql($sql2);
$sql3 = "UPDATE account SET balance=balance+'$amount' WHERE accID='$toAccountId'"; $sql3 = "UPDATE account SET balance=balance+'$amount' WHERE accID='$toAccountId'";
$result = queryMysql($sql3); $result = queryMysql($sql3);
$sql2 = "INSERT INTO transaction(username, transtype, toID, acctype, amount)
SELECT username, 'Transfer', '$toAccountId', acctype, '$amount' FROM account WHERE
accID='$fromAccountId'";
$result = queryMysql($sql2);
$sql2 = "INSERT INTO transaction(username, transtype, toID, acctype, amount)
SELECT username, 'Transfer', accid, acctype, '$amount' FROM account WHERE
accID='$toAccountId'";
$result = queryMysql($sql2);
$errorMessage .= "<p>Transfer completed.</p>"; $errorMessage .= "<p>Transfer completed.</p>";
} }
else { else {

View File

@@ -33,36 +33,18 @@ function Withdraw($userName,$accountId,$amount) {
if ($count == 1){ if ($count == 1){
$sql2 = "UPDATE account SET balance=balance-'$amount' WHERE username='$userName' and accID='$accountId'"; $sql2 = "UPDATE account SET balance=balance-'$amount' WHERE username='$userName' and accID='$accountId'";
$result = queryMysql($sql2); $result = queryMysql($sql2);
$sql2 = "INSERT INTO transaction(username, transtype, toID, acctype, amount)
SELECT username, 'Withdraw', accID, acctype, '$amount' FROM account WHERE
accID='$accountId'";
$result = queryMysql($sql2);
$errorMessage .= "<p>Withdraw completed.</p>"; $errorMessage .= "<p>Withdraw completed.</p>";
} else { } else {
$errorCount++; $errorCount++;
$errorMessage .= "Invalid user name/account number.<br />"; $errorMessage .= "Invalid user name/account number.<br />";
} }
/*
if (!@mysql_select_db($db_name, $db_connect)) {
$errorMessage .= "<p>Connection error. Please try again later.</p>";
$errorCount++;
}
else {
// verify the account belongs to the user
$sql = "SELECT * FROM account WHERE username='$userName' and accountid='$accountId'";
$result = mysql_query($sql);
// If result matched $myusername and $mypassword, table row must be 1 row
$count = mysql_num_rows($result);
if($count == 1){
// record login to login_history table
$sql2 = "UPDATE account SET balance=balance-'$amount' WHERE username='$userName' and accountid='$accountId'";
$result = mysql_query($sql2);
$errorMessage .= "<p>Withdraw completed.</p>";
}
else {
$errorCount++;
$errorMessage .= "Invalid user name/account number.<br />";
}
}
*
*/
} }
} }