gpt4 book ai didi

php - 为什么 'Quantity' 值不显示任何值?

转载 作者:行者123 更新时间:2023-11-29 07:52:15 26 4
gpt4 key购买 nike

我尝试显示数据库表中的数量值,但浏览器中未显示 $quantity 值。为什么?

enter image description here

<?php

include('connection.php');

# cartexe.php will perform all actions on cart.php

// add Item to Cart
if(isset($_POST['addItemToCart']))
{
// initialize index.php variables
$productName = $_POST['productName'];
$price = $_POST['price'];
$description = $_POST['description'];
$quantity = 0;

// check the cart table to see if the product has been previously added
$smtp = $conn->prepare('SELECT * FROM cart WHERE Product_Name = :product'); // prepare a statement to fetch the quanity for a particular pprodut... the statement is not executed but merely prepared to do so.
$smtp->bindParam(':product', $productName, PDO::PARAM_STR); //bind the productNAme with whatever data supplied hence the statement after : above will be replaced with the actually data.. In additional the statement is set as string hence PDO::PRAM_STR
$smtp->execute();//finally run the statment

//var_dump($smtp);
//find the number of rows affected
$result = $smtp->fetch(PDO::FETCH_NUM);
// var_dump($smtp);


//the data does existed
if($result > 0)
{
$row = $smtp->fetch(PDO::FETCH_ASSOC);
echo " DATA FOUND";
echo $row['Quantity'];

//$quantity++; // increment the quanity if data found
}
//no match found
else
{
echo ' No data found';
}

}

?>

最佳答案

看来你不需要先fetch try

$smtp = $conn->prepare('SELECT * FROM cart WHERE Product_Name = :product'); // prepare a statement to fetch the quanity for a particular pprodut... the statement is not executed but merely prepared to do so. 
$smtp->bindParam(':product', $productName, PDO::PARAM_STR); //bind the productNAme with whatever data supplied hence the statement after : above will be replaced with the actually data.. In additional the statement is set as string hence PDO::PRAM_STR
;//finally run the statment



//the data does existed
if( $smtp->execute() )
{
$row = $smtp->fetch(PDO::FETCH_ASSOC);
echo " DATA FOUND";
echo $row['Quantity'];

//$quantity++; // increment the quanity if data found
}

关于php - 为什么 'Quantity' 值不显示任何值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26110341/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com