From ff341372b9a4f10e1f72225940002a8d8a91d28b Mon Sep 17 00:00:00 2001 From: ry1015 Date: Sun, 16 Nov 2014 23:34:19 -0800 Subject: [PATCH] Another update --- f8l_exception/Fifteen Functions.txt | 13 +++++++- f8l_exception/admin.php | 2 +- f8l_exception/admin_home.php | 26 ++++++++++++++-- f8l_exception/includes/inc_adminFunctions.php | 25 +++++++++++++-- f8l_exception/includes/inc_dbConnect.php | 6 ++-- f8l_exception/includes/inc_validateLogin.php | 22 +++++++------ f8l_exception/my_accounts.php | 31 +++++++++++++++++-- f8l_exception/styles.css | 8 ++++- 8 files changed, 111 insertions(+), 22 deletions(-) diff --git a/f8l_exception/Fifteen Functions.txt b/f8l_exception/Fifteen Functions.txt index a8eb30e..ff81692 100644 --- a/f8l_exception/Fifteen Functions.txt +++ b/f8l_exception/Fifteen Functions.txt @@ -46,4 +46,15 @@ F8L Exception -- 15 Functions: 14. Increase Credit Card Limit (Admin) 15. Daily Transactions Tally (Admin) - show the sum of all deposits and withdraws for one day \ No newline at end of file + show the sum of all deposits and withdraws for one day + +STORED PROCEDURE +DROP PROCEDURE IF EXISTS getLowBalance; +DELIMITER // +CREATE PROCEDURE getLowBalance() +BEGIN +SELECT username, acctype, balance +FROM account +where balance <= 200; +END // +DELIMITER; diff --git a/f8l_exception/admin.php b/f8l_exception/admin.php index dc20df3..13b8672 100644 --- a/f8l_exception/admin.php +++ b/f8l_exception/admin.php @@ -30,7 +30,7 @@ if (isset($_POST['Submit'])){ $password = validateInput($_POST['pass'],"Password"); //Check if there is an error on userName and/or password. if ($errorMessage == ""){ - $result = queryMySQL("SELECT username,password FROM Users WHERE username='$userName' AND password='$password'"); + $result = queryMysql("SELECT username,password FROM Users WHERE username='$userName' AND password='$password'"); $num = $result->num_rows; if ($result->num_rows == 0) diff --git a/f8l_exception/admin_home.php b/f8l_exception/admin_home.php index fc234d4..63b82a2 100644 --- a/f8l_exception/admin_home.php +++ b/f8l_exception/admin_home.php @@ -34,6 +34,7 @@ if (isset($_POST['view'])){ if ($_POST['view'] == 'lowBalance'){ echo <<<_END +

LOW BALANCE

@@ -43,9 +44,26 @@ if (isset($_POST['view'])){ _END; viewLowBalance(); } elseif ($_POST['view'] == 'increaseLimit'){ - echo "increase limit!"; + echo <<<_END +

INCREASE CREDIT CARD LIMIT

+
Username
+ + + + + +_END; + increaseLimit(); } elseif ($_POST['view'] == 'offerCredit'){ - echo "offer a credit card!"; + echo <<<_END +

OFFER CREDIT CARD

+
UsernameMax LimitChecking Balance
+ + + + +_END; + offerCredit(); } echo <<<_END
UsernameBalance
@@ -59,4 +77,8 @@ function viewLowBalance(){ function increaseLimit(){ increaseCCLimit(); } + +function offerCredit(){ + offerCC(); +} ?> diff --git a/f8l_exception/includes/inc_adminFunctions.php b/f8l_exception/includes/inc_adminFunctions.php index a830990..045b5ad 100644 --- a/f8l_exception/includes/inc_adminFunctions.php +++ b/f8l_exception/includes/inc_adminFunctions.php @@ -2,11 +2,32 @@ include 'functions.php'; function lowBalance(){ - $result = queryMysql("SELECT username, acctype, balance from account WHERE balance <= 200"); + //$result = queryMysql("SELECT username, acctype, balance from account WHERE balance <= 200"); + $result = queryMysql("Call getLowBalance"); $num = $result->num_rows; for ($j = 0; $j < $num; $j++){ $row = $result->fetch_array(MYSQLI_ASSOC); - echo "" . $row['username'] . "" . $row['acctype'] . "$" . $row['balance'] . ""; + echo "" . $row['username'] . "" . $row['acctype'] . "$ " . number_format($row['balance'], 2, '.', ',') . ""; + } +} + +function offerCC(){ + $result = queryMysql("SELECT username, balance from account WHERE balance > 10000"); + $num = $result->num_rows; + for ($j = 0; $j < $num; $j++){ + $row = $result->fetch_array(MYSQLI_ASSOC); + echo "" . $row['username'] . "$ " . number_format($row['balance'], 2, '.', ',') . ""; + } +} + +function increaseCCLimit(){ + $result = queryMysql("SELECT account.username, account.balance, creditcard.maxlimit from account,creditcard WHERE (account.acctype = 'checking' and " + . "account.balance > 2 * creditcard.maxlimit and account.username = creditcard.username)"); + $num = $result->num_rows; + for ($j = 0; $j < $num; $j++){ + $row = $result->fetch_array(MYSQLI_ASSOC); + echo "" . $row['username'] . "$ " . number_format($row['maxlimit'], 2, '.', ',') . + "$ " . number_format($row['balance']) . ""; } } ?> \ No newline at end of file diff --git a/f8l_exception/includes/inc_dbConnect.php b/f8l_exception/includes/inc_dbConnect.php index 480081d..0c81376 100644 --- a/f8l_exception/includes/inc_dbConnect.php +++ b/f8l_exception/includes/inc_dbConnect.php @@ -1,11 +1,13 @@ connect_error) die ($connection->connect_error); +//$db_connect = mysql_connect("$db_host", "$db_username", "$db_password")or die("cannot connect"); //mysql_select_db("$db_name")or die("cannot select DB"); ?> \ No newline at end of file diff --git a/f8l_exception/includes/inc_validateLogin.php b/f8l_exception/includes/inc_validateLogin.php index 6d449eb..1e55f61 100644 --- a/f8l_exception/includes/inc_validateLogin.php +++ b/f8l_exception/includes/inc_validateLogin.php @@ -1,34 +1,36 @@ real_escape_string($myusername); + $mypassword = $connection->real_escape_string($mypassword); // check login and password for validity - $sql = "SELECT * FROM user WHERE username='$myusername' and password='$mypassword'"; - $result = mysql_query($sql); + $sql = "SELECT * FROM users WHERE username='$myusername' and password='$mypassword'"; + $result = queryMysql($sql); // If result matched $myusername and $mypassword, table row must be 1 row - $count = mysql_num_rows($result); + $count = $result->num_rows; if($count == 1){ // record login to login_history table - $sql2 = "INSERT INTO login_history (login) VALUES ('$myusername')"; - $result = mysql_query($sql2); + //$sql2 = "INSERT INTO login_history (login) VALUES ('$myusername')"; + //$result = queryMysql($sql2); } else { $errorCount++; $errorMessage .= "Wrong User Name or Password.
\n"; } - mysql_close($db_connect); + $result->close(); + //mysql_close($db_connect); return $myusername; } ?> \ No newline at end of file diff --git a/f8l_exception/my_accounts.php b/f8l_exception/my_accounts.php index c69608f..c6dcbec 100644 --- a/f8l_exception/my_accounts.php +++ b/f8l_exception/my_accounts.php @@ -13,9 +13,27 @@

My Accounts

num_rows == 0){ + echo "

You have no accounts open.

"; + } else { + echo ""; + echo " + + + + "; + $num = $result->num_rows; + for ($j = 0; $j < $num; $j++){ + $row = $result->fetch_array(MYSQLI_ASSOC); + echo ""; + } + $result->close(); + } + /* if ($db_connect === FALSE) echo "

Unable to connect to the database server.

" . "

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

"; @@ -23,9 +41,11 @@ function showAccounts($userName) { if (!@mysql_select_db($db_name, $db_connect)) echo "

Connection error. Please try again later.

"; else { + * + * $SQLstring = "SELECT * from account WHERE username='$userName'"; - + * $QueryResult = @mysql_query($SQLstring, $db_connect); if (mysql_num_rows($QueryResult) == 0) echo "

You have no accounts open.

"; @@ -36,6 +56,9 @@ function showAccounts($userName) { "; + * + * + while (($Row = mysql_fetch_assoc($QueryResult)) !== FALSE) { echo ""; @@ -47,7 +70,9 @@ function showAccounts($userName) { } mysql_close($db_connect); } - return ($retval); + * + */ + //return ($retval); } $userName = ""; diff --git a/f8l_exception/styles.css b/f8l_exception/styles.css index 98591fe..cf5faa1 100644 --- a/f8l_exception/styles.css +++ b/f8l_exception/styles.css @@ -14,8 +14,14 @@ img { } table { - width: 100%; + width: 90%; + margin-left: auto; + margin-right: auto; } table, th, td{ border: 1px solid black; +} + +.tabletitle{ + text-align: center; } \ No newline at end of file
Account TypeAccount NumberBalance
" . $row['username'] . "" . $row['acctype'] . "$ " . number_format($row['balance'], 2, '.', ',') . "
Account Number Balance
{$Row['accounttype']}