2011-04-16 52 views
0

錯誤是致命錯誤:調用未定義的方法stdClass的:: retrieve_all_accounts()在/home/mjcrawle/public_html/cit0215/assignment5/onlinebanking/viewaccounts.php在線72PHP BD錯誤行72

我沒有得到任何html錯誤,所以我會離開它。

我的PHP代碼到錯誤是:

<?php 

require_once('footer_nav/navigation.inc.php'); 
require_once('../websiteconfig.inc.php'); 
require_once('../class/person_class.php'); 
require_once('../class/database.class.php'); 

/*Start Session*/ 
session_start(); 

$currentMember =unserialize($_session['currentMember']); 

/*DataBase*/ 
$db = new Database; 
$conn = $db->connection; 
?> 
<td width="16">&nbsp;</td> 
<td width="595"> 
</td> 
</tr> 

</div> 


<h2>Accounts</h2> 


</td> 
<table id="accounts" summary="Bank Account Balance Information"> 
<thread> 
    <tr> 
     <th>Account Number</th> 
     <th>Account Balance</th> 
    </tr> 
    </thead> 
<tbody>  
<php? 
/*Accounts*/ 
$currentMember->connection = $conn; 

這是我得到的錯誤線72:

$accounts = $currentMember->retrieve_all_accounts(); 

/* Loop Though Accounts*/ 
while($account = mysqli_fetch_assoc($account)) { 
    /* Retrieve Account Balance*/ 
$bankaccount = new Bankaccount ($account['BankAccountID']); 
$bankaccount->connection = $conn; 
$balance = mysqli_fetch_assoc($bankaccount->retrieve_current_balance()); 

echo '<tr>' . "\n"; 
echo "\t" . '<td class="account_number">' . $account['BankAccountID'] . '</td>' . "\n"; 
echo "\t" . '<td class="account_balance">$' . number_format($balance['CurrentBalance'], 2) . '</td>' . "\n"; 
echo '</tr>' . "\n"; 

} 

/*Closed DataBase*/ 
mysqli_close($db->connection); 

?> 
+2

也許沒有像retrieve_all_accounts()這樣的方法? – Robus 2011-04-16 15:30:02

回答

0

首先,您要使用此,在代碼的第一部分:

<php? 
/*Accounts*/ 
$currentMember->connection = $conn; 

如果你真的複製粘貼了這個,你在這裏有一個問題:這不是PHP代碼。

相反,你應該有:

<?php 
/*Accounts*/ 
$currentMember->connection = $conn; 

注意,一個PHP開始標記是<?php,而不是<php?


然後,你$currentMember變量被設置是這樣的:

$currentMember =unserialize($_session['currentMember']); 

看來這使得$currentMember只是在容器上,而不是將有一個retrieve_all_accounts()方法的類的實例。

所以,試圖調用該方法時:

$accounts = $currentMember->retrieve_all_accounts(); 

你得到一個致命的錯誤,因爲在你的$currentMember對象中沒有這樣的方法。

相關問題