[英]what's wrong with my code in sales controller?
undefined variable productdata, I dont knw what's happening with my code 未定义的变量productdata,我不知道我的代码发生了什么
case 'add_sale':
if (isset($_POST['select_product']) && $_POST['select_product']!= ''
&& isset($_POST['txt_amount']) && $_POST['txt_amount']!= 0 ){
$product = new product();
$productarr = $product->getProductById($_POST['select_product']);
foreach($productarr as $data){
$operation = $data[2]*$_POST['txt_amount'];
$subtotal = number_format($operation,2);
$productdata = array(
'idproduct'=>$data[0],
'product'=>$data[1],
'price'=>$data[2],
'amount'=>$_POST['txt_amount'],
'subtotal'=>$subtotal
);
}
$_SESSION['detalle'][] = $productdata;
echo "success";
}else{
echo 'something went wrong';
}
break;
declare $productdata = array();
声明$productdata = array();
just inside the 1st if() block. 就在第一个if()块中。 Actually, when your $productarr
will blank, it will never enter your foreach()
so at that time $productdata
in undefined variable 实际上,当您的$productarr
空白时,它将永远不会输入您的foreach()
因此当时$productdata
中的未定义变量
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.