我有一個類中使用一種方法來得到一個會話陣列信息的IAM通過一個for循環2使用每種方法中的循環1.計算物品的總量,2.將總價加起來,但似乎都沒有返回任何東西。即時通訊使用總金額來檢查它從IPN的mc_gross發佈的價值,如果這些值是相等的,我計劃將銷售提交到數據庫,因爲它已被驗證。對於即時獲得總價格即時得到0.00返回給我的方法。我認爲我的語法錯在這裏不知何故這裏是我的類購買兩種方法IAM有麻煩的是下面顯示的gettotalcost()和gettotalitems()是我的類。
<?php
class purchase {
private $itemnames; // from session array
private $amountofitems; // from session array
private $itemcost; //session array
private $saleid; //posted transaction id value to be used in sale and sale item tables
private $orderdate; //get current date time to be entered as datetime in sale table
private $lastname; //posted from ipn
private $firstname; //posted from ipn
private $emailadd; //uses sessionarray value
public function __construct($saleid,$firstname,$lastname)
{
$this->itemnames = $_SESSION['itemnames'];
$this->amountofitems =$_SESSION['quantity'];
$this->itemcost =$_SESSION['price'];
$this->saleid = $saleid;
$this->firstname = $firstname;
$this->lastname = $lastname;
$this->emailadd = $SESSION['username'];
mail($myemail, "session vardump ", echo var_dump($_SESSION), "From: [email protected]");
mail($myemail, "session vardump ",count($_SESSION['itemnames']) , "From: [email protected]");
}
public function commit()
{
$databaseinst = database::getinstance();
$databaseinst->connect();
$numrows = $databaseinst->querydb($query);
//to be completed
}
public function gettotalitems()
{
$numitems;
$i;
for($i=0; $i < count($this->amountofitems);$i++)
{
$numitems += (int) $this->amountofitems[$i];
}
return $numitems;
}
public function gettotalcost()
{
$totalcost;
$i;
for($i=0; $i < count($this->amountofitems);$i++)
{
$numitems = (int) $this->amountofitems[$i];
$costofitem =doubleval($this->itemcost [$i]);
$totalcost += $numitems * $costofitem;
}
return $totalcost;
}
}
?>
這裏是我創建類的一個實例,並嘗試使用它。
include(「purchase.php」);
$purchase = new purchase($_POST['txn_id'],$_POST['first_name'],$_POST['last_name']);
$fullamount = $purchase->gettotalcost();
$fullAmount = number_format($fullAmount, 2);
$grossAmount = $_POST['mc_gross'];
if ($fullAmount != $grossAmount) {
$message = "Possible Price Jack attempt! the amount the customer payed is : " . $grossAmount .
" which is not equal to the full amount. the price of the products combined is " . $fullAmount. "
the transaction number for which is " . $_POST['txn_id'] . "\n\n\n$req";
mail("XXXXXXXXXXXX", "Price Jack attempt ", $message, "From: [email protected]");
exit(); // exit
}
感謝您的幫助!
我也將這些行添加到我的構造函數中。郵件返回,vardump中沒有任何東西哦!
mail($myemailaddress, "session vardump ", var_dump($_SESSION), "From: [email protected]");
還添加
在session_start();
在構造函數的頂部,它不工作!幫助 好吧,我得到了vardump打印在一個單獨的PHP頁面,它給了我這個。 (9){[「token」] => string(32)「964885a70512d21933d139663a8fe48a」[「ID」] => string(19)「XXXXXXXX」[「username」] => string(19)「XXXXXX 「[」password「] => string(5)」XXX「[」admin「] => string(1)」0「[」set「] => string(4)」true「[」itemnames「] => [3] => string(30)「Naomh Ciaran:Pilgrim Islander」[2] => string(35)「(3){[0] => string(43) O Driscolls:Past and Present(2005)「} [」quantity「] => array(3){[0] => int(2)[1] => string(1)」1「[2] => string (1)「1」} [「price」] => array(3){[0] => string(5)「12.73」[1] => string(5)「23.99」[2] => string 5)「11.76」}}
你確定在創建類的時候$ _SESSION值設置正確並且會話已經啓動了嗎? – 2012-03-22 10:16:23
你爲什麼要寫「$ totalcost; $ i;」和「$ numitems; $ i;」明確地在函數中? – 2012-03-22 10:26:02
@OM永恆的東西只是我習慣用java來完成的方式。 – eoin 2012-03-22 11:03:52