我正在电子商务网站上工作,一切都很完美。现在我在结账页面。客户首先填写账单明细,然后下订单。
我在数据库中收到帐单详细信息但没有收到订单详细信息。
checkout.php
<form action="process.php" method="Post">
<!--bill details field-->
//fields
<!--end bill details field-->
<!--shipping detials filed-->
//Shipping details
<!--end shipping detials filed-->
<!--order detials are(Session is working perfectly)-->
if(!empty($_SESSION['product_cart'])):
foreach($_SESSION['product_cart'] as $key=>$product):
?>
<li>
<div class="order-list">
<img src="admin/images/products/<?php echo $product['p_images'];?>">
<?php echo $product['p_brandname'];?>
<div class="circle-qty"><?php echo $product['quantity'];?></div>
<span>$<?php echo $product['p_total'];?></span>
<input type="hidden" name="o_product_name[]" value="<?php echo $product['p_brandname'];?>">
<input type="hidden" name="o_product_qty[]" value="<?php echo $product['quantity'];?>">
<input type="hidden" name="o_product_single_cost[]" value="<?php echo $product['p_currentprice'];?>">
<input type="hidden" name="o_product_totalcost[]" value="<?php echo $product['p_total'];?>">
</div>
</li>
<?php $total_amount[]= $product['p_total'];//getting all the product price and assigning to array for total amount?>
<?php endforeach;?>
<li class="checkout-total"><div><h2>Total</h2><span>$<?php echo array_sum($total_amount);?></span></div></li>
<?php endif;?>
</form>
我收到错误
Warning: trim() expects parameter 1 to be a string, array given in
Warning: trim() expects parameter 1 to be string, array given in
Warning: trim() expects parameter 1 to be string, array given in
Warning: trim() expects parameter 1 to be string, array given in
Process.php
echo $o_product_name=$conn->real_escape_string(trim($_POST['o_product_name']));
echo $o_product_qty=$conn->real_escape_string(trim($_POST['o_product_qty']));
echo $o_product_single_cost=$conn->real_escape_string(trim($_POST['o_product_single_cost']));
echo $o_product_totalcost=$conn->real_escape_string(trim($_for each_product_totalcost']));
我试图显示值但不起作用。即便我尝试使用内爆函数,但这也无效。
foreach($o_product_name as $key => $value)
{
echo $key." has the value". $value;
}
//second tried
$string=implode(",",$o_product_name);
echo $string;
你能帮助我吗?
答案 0 :(得分:0)
$_POST['o_product_name']
是一个数组。您无法在trim函数中传递Array。在process.php文件中,您需要循环遍历$ _POST数组。
foreach($_POST['o_product_name'] as $key=>$value)
{
echo $o_product_name=$conn->real_escape_string(trim($_POST['o_product_name'][$key]));
}
另一个相同。请检查语法错误,因为我没有测试过代码,但它应该可以正常工作。
感谢。
答案 1 :(得分:0)
在process.php中,你不能在trim()方法中使用数组
$o_product_name=$_POST['o_product_name'];
$o_product_qty=$_POST['o_product_qty'];
$o_product_single_cost=$_POST['o_product_single_cost'];
$o_product_totalcost=$_POST['o_product_totalcost'];
foreach($o_product_name as $key => $value)
{
echo $key." has the value". $conn->real_escape_string(trim($value));;
}