데이터베이스 테이블에서 수량 값을 표시하려고 $quantity
하는데 브라우저에 값이 표시되지 않습니다 . 왜?
<?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';
}
}
?>
첫 번째 가져 오기 시도가 필요하지 않은 것 같습니다.
$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
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다