Good Day,我的任务是使用PHP在我们的网站上获得原始价格和折扣价。以前原始价格已经存在,现在我试图通过在客户管理系统中添加变量来添加第二个价格。问题是我得到
注意:未定义索引:
即使我在原始价格旁边加上折扣价也是如此。我在phpmyadmin数据库中为新的折扣价选项添加了新列,但仍然收到该索引错误。
任何帮助将不胜感激,并且无法通过代码和屏幕截图来说明情况。
price error phpmyadmin columns
具有原始价格和折扣价格的代码(“ d_price”是具有不明索引的代码)
1。
<div class="col-md-12"><hr></div>
<div class="col-md-3">ORIGINAL PRICE</div>
<div class="col-md-9">
<input type="number" class="form-control" name="price" placeholder="Original Price"
value="<?php
if(isset($_POST['price'])) {
echo($_POST['price']);
} else {
echo($rowProduct['price']);
} ?>">
</div>
<div class="col-md-12"><hr></div>
<div class="col-md-3">DISCOUNTED PRICE</div>
<div class="col-md-9">
<input type="number" class="form-control" name="d_price" placeholder="Discounted Price"
value="<?php
if(isset($_POST['d_price'])) {
echo($_POST['d_price']);
} else {
echo($rowProduct['d_price']);
} ?>">
</div>
2。
<div class="col-md-12">
<div class="col-md-6 text-align-center">
<h4>ORIGINAL PRICE</h4>
<strike><h4><?php echo($rowProduct['price']); ?> PHP</h4></strike>
</div>
<div class="col-md-6 text-align-center">
<h4>DISCOUNTED PRICE</h4>
<h4><?php echo($rowProduct['d_price']); ?> PHP</h4>
</div>
</div>
3。 (这是保存按钮的if语句片段)
if (isset($_POST['submit']) && $_POST['submit'] == 'SAVE')
{
$price = $_POST['price'];
$d_price = $_POST['d_price'];
再次使用“ price”正常工作,而“ d_price”显示错误。希望我提供了足够的信息,不要让我的问题受到质疑。
我认为这是$ rowProduct起源的地方
$producttagid = isset($_GET['t']) ? $_GET['t'] : 1;
$merchantid = isset($_GET['m']) ? $_GET['m'] : NULL;
$rowProduct = $mcProduct->SelectObj_ByProductId($db, $productid);
$lstProductTag = $mcProductTag->SelectLst($db);
$lstProductTagLink = $mcProductTagLink->SelectLst_ByProductId($db, $productid);
$lstMerchant = $mcMerchant->SelectLst($db, 1, 10000);
$productid = $mcProduct->InsertObj($db, $merchantid, $title, $subtitle, $body, $recstatus, $price, $d_price, $qty, $createddate, $createdby, $featured, $packageid, $expirationdays);
这是我的phpmyadmin数据库的屏幕快照,我已经在“产品”行中添加了d_price,但仍获得未识别的索引。我会提供尽可能多的信息。
我认为这些代码行通过PDO与SQL数据库交互
编辑:这是SelectObj_ByProductId的所有位置(使用记事本++搜索)
C:\xampp\htdocs\mwc_canuto\-api\ProductsBookmarkToggle.api.php (1 hit)
Line 65: $api['productData'] = $api['productModel']->SelectObj_ByProductId(
C:\xampp\htdocs\mwc_canuto\cards\info-detailed.vc.php (2 hits)
Line 45: $rowProduct = $mcProduct->SelectObj_ByProductId($db, $productid);
Line 54: $rowProduct = $mcProduct->SelectObj_ByProductId($db, $productid);
C:\xampp\htdocs\mwc_canuto\cards\info.vc.php (2 hits)
Line 46: $rowProduct = $mcProduct->SelectObj_ByProductId($db, $productid);
Line 65: $rowProduct = $mcProduct->SelectObj_ByProductId($db, $productid);
C:\xampp\htdocs\mwc_canuto\clinic\info-detailed.vc.php (2 hits)
Line 45: $rowProduct = $mcProduct->SelectObj_ByProductId($db, $productid);
Line 54: $rowProduct = $mcProduct->SelectObj_ByProductId($db, $productid);
C:\xampp\htdocs\mwc_canuto\cms\products_edit.vc.php (1 hit)
Line 151: $rowProduct = $mcProduct->SelectObj_ByProductId($db, $productid);
C:\xampp\htdocs\mwc_canuto\_mc\Product.mc.php (1 hit)
Line 205: public function SelectObj_ByProductId($db, $productid) {
编辑:我在似乎是插入对象的函数中添加了d_price,但仍然得到了不确定的索引
/********** Insert Object **********/
public function InsertObj($db, $merchantid, $title, $subtitle, $body, $recstatus, $price, $d_price, $qty, $createddate, $createdby, $featured, $packageid, $expirationdays) {
$stmt = $db->prepare(
" INSERT INTO `product`
(merchantid, title, subtitle, body, recstatus, price, d_price, qty, createddate, createdby, featured, packageid, expirationdays)
VALUES
(:merchantid, :title, :subtitle, :body, :recstatus, :price, :d_price, :qty, :createddate, :createdby, :featured, :packageid, :expirationdays) "
);
// cast bit type data to int else it wont save properly
$featured = (int)$featured;
$stmt->bindValue(':merchantid', $merchantid, PDO::PARAM_INT);
$stmt->bindValue(':title', $title, PDO::PARAM_STR);
$stmt->bindValue(':subtitle', $subtitle, PDO::PARAM_STR);
$stmt->bindValue(':body', $body, PDO::PARAM_STR);
$stmt->bindValue(':recstatus', $recstatus, PDO::PARAM_INT);
$stmt->bindValue(':price', $price, PDO::PARAM_STR);
$stmt->bindValue(':d_price', $d_price, PDO::PARAM_STR);
$stmt->bindValue(':qty', $qty, PDO::PARAM_INT);
$stmt->bindValue(':createddate', $createddate, PDO::PARAM_STR);
$stmt->bindValue(':createdby', $createdby, PDO::PARAM_STR);
$stmt->bindValue(':featured', $featured, PDO::PARAM_INT);
$stmt->bindValue(':packageid', $packageid, PDO::PARAM_INT);
$stmt->bindValue(':expirationdays', $expirationdays, PDO::PARAM_INT);
$stmt->execute();
$insertId = $db->lastInsertId();
return $insertId;
}