Transfer

connect_error){ echo "

Unable to connect to the database server.

" . "

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

"; $errorCount++; } else { // verify the account belongs to the user $query = "SELECT * FROM account WHERE username='$userName' and accID='$fromAccountId'"; $result = queryMysql($query); // If result matched $myusername and $accountId, table rows must be 1 row $count = $result->num_rows; if($count == 1){ // record transfer to both accounts $sql2 = "UPDATE account SET balance=balance-'$amount' WHERE username='$userName' and accID='$fromAccountId'"; $result = queryMysql($sql2); $sql3 = "UPDATE account SET balance=balance+'$amount' WHERE accID='$toAccountId'"; $result = queryMysql($sql3); $errorMessage .= "

Transfer completed.

"; } else { $errorCount++; $errorMessage .= "Invalid user name/account number.
"; } } } function displayForm() { ?>

Enter from account number, to account number and transfer amount.

From Account Number:

To Account Number:

Transfer Amount:



"; // if submit button is clicked, get accountNumber and amount if (isset($_POST['Submit'])) { $fromAccountNumber = validateInput($_POST['fromAccountNumber'],"From Account Number"); $toAccountNumber = validateInput($_POST['toAccountNumber'],"To Account Number"); $amount = validateInput($_POST['amount'],"Transfer Amount"); if ($amount <= 0) { $errorMessage .= "Invalid amount.
"; $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 { if ($showForm == TRUE) { displayForm(); // new page load } else { // make transfer transfer($userName,$fromAccountNumber,$toAccountNumber,$amount); echo $errorMessage."
"; } } ?>