0

我正在复制 PHP Programming with MySQL(第 10 章)的作业,并试图让它正常工作。我收到以下错误:致命错误:调用未定义的方法 OnlineStore::setStoreID()。我不明白为什么会出现问题。有人能帮助我吗?

谢谢你。

这是php代码:

if (class_exists("OnlineStore")) {
    if (isset($_SESSION['currentStore']))
    $Store = unserialize($_SESSION['currentStore']);
    else {
        $Store = new OnlineStore();
    }

$Store->setStoreID($storeID);
$storeInfo = $Store->getStoreInformation();
if (isset($_GET['ItemToAdd']))
    $Store->addItem();
}

else {
$ErrorMsgs[] = "The OnlineStore class is not available!";
$Store = NULL;
}
?>

这是其他代码的一部分:

<?php
class OnlineStore {
private $DBConnect = NULL;
private $storeID = "";
private $inventory = array();
private $shoppingCart = array();
}

function __construct() {
include("inc_OnlineStoreDB.php");
$this->DBConnect = $DBConnect;
}

function __destruct() {
if (!$this->DBConnect->connect_error)
$this->DBConnect->close();
}

function setStoreID($storeID) {
if ($this->storeID != $storeID) {
    $this->storeID = $storeID;
    $SQLString = "SELECT * FROM inventory " . " where storeID = '" . $this-    >storeID . "'";
    $QueryResult = @$this->DBConnect->query($SQLString);
    if ($QueryResult === FALSE) {
        $this->storeID = "";
    }
    else {
        $this->inventory = array();
        $this->shoppingCart = array();
        while (($Row = $QueryResult->fetch_assoc())
                !== NULL) {
            $this->inventory[$Row['productID']] = array();
            $this->inventory[$Row['productID']] ['name'] =     $Row['name'];
            $this->inventory[$Row['productID']] ['description'] =     $Row['description'];
            $this->inventory[$Row['productID']] ['price'] =     $Row['price'];
            $this->shoppingCart[$Row['productID']] = 0;
        }
    }
}
}
4

1 回答 1

1

在这段代码中:

class OnlineStore {
private $DBConnect = NULL;
private $storeID = "";
private $inventory = array();
private $shoppingCart = array();
}

您正在使用右花括号提前完成课程,之后您定义的所有函数都在课程之外。

于 2012-11-30T18:42:55.880 回答