Good Day, I am tasked to have an original and discounted price in our website, using PHP. Previously the original price is already present, now I am trying to add a second price by adding variables in the customer management system. The problem is that I get
Notice: Undefined index:
even when I add a discounted price value alongside the original price. I added a new column for the new discounted price option in my phpmyadmin database but I still get that index error.
Any help would be appreciated and ill explain the situation with codes and screenshots.
price error phpmyadmin columns
codes with original price and discounted price (the "d_price" is the one with unidentified index)
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. (this is the if statement snippet for the save button)
if (isset($_POST['submit']) && $_POST['submit'] == 'SAVE')
{
$price = $_POST['price'];
$d_price = $_POST['d_price'];
Again 'price' works normally while 'd_price' shows the error. I hope I have provided enough information to not get my question downvoted.
I think this is where $rowProduct originates:
$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);
heres a screenshot of my phpmyadmin database, I already added d_price in the Product row but I still get unidentified index. Im providing as much information as I can.
I think these lines of code interact with the SQL database via PDO
EDIT: here are all the locations of SelectObj_ByProductId (searched with notepad++)
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) {
EDIT: I added d_price in what seems to be the insert object function, I still get unidentified index
/********** 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;
}
PHP
` is line 139? If so, use a conditional statement for it also or a ternary operator. – Funk Forty Niner Nov 21 '18 at 02:26