使用php将paypal标准与购物车中的多个项目集成

时间:2015-11-19 05:24:45

标签: php mysqli paypal shopping-cart

我已经使用mysqli数据库从php创建了一个网站http://www.mandyevansartist.com,现在我正在尝试将paypal集成到结帐中。

我的最新尝试是

 $checkout = mysqli_query($con,"SELECT * FROM cart where cookieId =     '".GetCartId()."'");
while   ($row = mysqli_fetch_array($checkout)){
$num = "1"; 
$num++;
echo  '<br / >';
echo  'a '.$row['product'];
echo ' of '.$row['name'];
echo ' at '.$row['price'];

echo '<form action="https://www.sandbox.paypal.com/cgi-bin/webscr"    method="post">';

$count = 1;
$count = $count + 1;
echo "<input type='hidden' name='item_name_".$count."'  value=".$row['name']."'>";
echo "<input type='hidden' name='item_number_".$count."' value='".$count."'>";
echo "<input type='hidden' name='amount_".$count."'     value='".$row['price']."'>";


echo'<input type="hidden" name="cmd" value="_cart">';
echo'<input type="hidden" name="business" value="email@mail.com">';
echo'<input type="hidden" name="currency_code" value="AU">';
echo'<input type="hidden" name="return" value="http://www.mandyevansartist.com">';
echo'<input type="hidden" name="upload" value="1">';
echo'<input type="submit" value="paypal">'; 
echo '</form>';
 }

我尝试通过按一个提交按钮将两个项目发送到沙箱付款页面,经历了多次尝试。这是第三天,我在第一天的尝试更成功,现在已经失败了。

此代码的结果是产品,名称和价格从数据库中出来并打印出来,每个项目都有一个提交按钮 - 当按下任一按钮时,结果是“错误 - 空购物车& #39;

添加&#39; foreach&#39;在计算之后,我现在有许多重复的物品进入购物车

echo' <form action="https://www.sandbox.paypal.com/cgi-bin/webscr"  method="post">';

$checkout = mysqli_query($con,"SELECT * FROM cart where cookieId =  '".GetCartId()."'");
while   ($row = mysqli_fetch_array($checkout)){
echo  '<br / >';
echo  'a '.$row['product'];
echo ' of '.$row['name'];
echo ' at '.$row['price'];
$name = $row['name'];
$price= $row['price'];
$id= GetCartId();
$count = 1;
foreach($row as $id):
echo'<input type="hidden" name="cmd" value="_cart">';
echo'<input type="hidden" name="upload" value="1">';
echo'<input type="hidden" name="currency_code" value="AU">';
echo'<input type="hidden" name="business" value="email@mail.com">';
echo'<input type="hidden" name="item_name_'.$count.'"  value="'.$name.'">';
echo'<input type="hidden" name="amount_'.$count.'" value="'.$price.'">';
$count++;
 endforeach;
}
echo'<input type="submit" value="PayPal">';
echo'</form>';

0 个答案:

没有答案