Jump to content

Php view tansaction Log query issues.


mlj0102

Recommended Posts

I get this error when I run the query:  and I have no idea how to fix..  I have been staring at this for days.

 

 

Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, null given in /onlinebanking/viewtransactions.php on line 65

 

This is my view transactions page

<?php
 //viewtransaction 
 	require_once('../websiteconfig.inc.php');
   		require_once(ABSOLUTE_PATH . 'class/database.class.php');
	require_once(ABSOLUTE_PATH . 'class/person.class.php'); 
	require_once(ABSOLUTE_PATH . 'class/bankaccount.class.php');



	/*START SESSION*/
	session_start();

	$currentMember = unserialize($_SESSION['currentMember']);
	$currentMember->connection = $conn;

	/*Database*/
	$db = new Database;
	$conn = $db->connection;

	$bank_account = $_GET['q'];

	?>


       
        </div>
        <link href="../_assets/stylesheets/css_dd_bankingnav.css" rel="stylesheet" type="text/css" />
        <link href="../_assets/stylesheets/style.css" rel="stylesheet" type="text/css" />
        <div class="container" id="shadow">
        <div>
      		<?php 

                include(ABSOLUTE_PATH . 'header.inc.php');
            ?>


                <div>
                <h1 class="body" align="center">Accounts</h1>
                
                <?php
                include(ABSOLUTE_PATH . 'onlinebanking/onlinebankingnav.inc.php');
               ?>
               
               

                <table id="accounts" summary="Bank Account Balance Information" border="3" align="center">
                <thead>
                	<tr>
                        <th bgcolor="#CCCCCC">Account ID</th>
                        <th bgcolor="#CCCCCC">Transaction Date</th>
                        <th bgcolor="#CCCCCC">Transaction Type</th>
                        <th bgcolor="#CCCCCC">Transaction Amount</th>
                        <th bgcolor="#CCCCCC">Current Balance</th>
                     </tr>                     
                </thead>
                <tbody>
<?php	

$bankaccount = new Bankaccount($account['BankAccountID']);
$bankaccount->connection = $conn;

/*Loop thorugh account - Grabs data*/
while($transaction = mysqli_fetch_assoc($transactionbalance)) {
$transactionbalance = $bankaccount->retrieve_transactions($transaction['BankAccountID']);

//looks for account data
$querydata = mysqli_num_rows($transactionbalance);

//Looks for transcations
	if ($querydata == 0) {
		echo ('There is no transaction history on this account');
	}
		else {
	}	
				echo '<tr>' . "\n";
				echo "\t" . '<td>' . $transaction['BankAccountID'] . '</td>' . "\n";
				echo "\t" . '<td>' . $accounttype['TransactionDate'] . '</td>' . "\n";
				echo "\t" . '<td>' . $accounttype['TransactionType'] . '</td>' . "\n";
				echo "\t" . '<td>$' . number_format($accounttype['TransactionAmount'], 2) . '</td>' . "\n";
				echo "\t" . '<td>$' . number_format($transaction['CurrentBalance'], 2) . '</td>' . "\n";
				echo '<tr>' . "\n";

	}


	/*Close DB*/
	mysqli_close($db->connection);		
?>

	</tbody>
        </table>
        <br>

               
                </div><!--End of main content-->
		<?php 
                include(ABSOLUTE_PATH . 'footer.inc.php');
            ?>

</div><!--end of header-->



 

This is my bankaccount.class page

 

 

<?php
/*Bankaccount Class*/
class Bankaccount {

/*attributes for the first and last name of the class*/
private $accountid;
private $memberid;
private	$accounttypeid;
private	$accounttypename;
public 	$connection;

/*Constructs the function*/
function __construct($accountid, $accounttypeid){
	$this->accountid = $accountid;
	$this->accounttypeid = $accounttypeid;
	} //end constructor

/*Destroys the function*/
function __destruct(){
} //ends destructor 

/*Get funtion*/
public function __get($name) {
	return $this->$name;
} // Ends get funtction

/*Use the set function*/
public function __set($name, $value) {
	$this->$name=$value;
} //End set function


/*This is what retrieves the values from memmory*/
public function retrieve_current_balance() {
	$balance_query = "SELECT CurrentBalance UserID FROM BankAccount WHERE BankAccountID = " . $this->accountid . " LIMIT 0,1";		
	$result = mysqli_query($this->connection, $balance_query);
	return $result;
}

This is the part of my bankaccount.class that actually involves viewing my transactions

<?php	
//query for transactions
public function retrieve_transactions() {
	$transaction_query = "SELECT tl.TransactionDate, tt.TransactionType, tl.TransactionAmount FROM TransactionLog tl INNER JOIN TransactionType tt ON tl.TransactionTypeID = tt.TransactionTypeID WHERE BankAccountID = " . $this->accountid . " LIMIT 0,1";	
	$result = mysqli_query($this->connection, $transaction_query);
	$db_array = mysqli_fetch_array($results);
	return $result;
}
?>

<?php	
/*Function validates user account for user ID*/
public function validate_useraccount(){
	$account_query = "SELECT UserID FROM BankAccount WHERE UserID = " . $this->accountid;
	$results = mysqli_query($this->connection, $account_query);
	$db_array = mysqli_fetch_array($results);
	$return_value = 1;

			if(count($db_array()) < 1) 
			{ 
				$return_value = 0; 
			}  
				return $return_value;
				}

/*Deposit*/
public function deposit($UserID=0, $BankAccountID=0, $DepositAmount=0){
	$getbalance = mysqli_fetch_assoc($this->retrieve_current_balance()); $currentbalance = $getbalance['CurrentBalance'];
	$today = date('Y-m-d', mktime());

	/*Deposit Funds*/
	$newbalance = $currentbalance + $DepositAmount;
	$deposit = mysqli_query($this->connection, "UPDATE BankAccount SET CurrentBalance = $newbalance WHERE BankAccountID = $BankAccountID");

	if($deposit){ //transaction completed

	/*Update Transaction log*/
	$log_query = "INSERT INTO TransactionLog (TransactionTypeID, BankAccountID, UserID, TransactionAmount, TransactionDate) VALUES (1, $BankAccountID, $UserID, $DepositAmount, $today')";	

	mysqli_query($this->connection, $log_query);
	}

	/*New Balance*/
	return $newbalance;	

}
} //End of class

?>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.