paypal获得多个item_number

时间:2015-10-08 13:29:45

标签: php paypal

我创建了一个paypal购物车表单,其中添加了多个付款产品:

        <?php
        $i=1;
        foreach($p_result as $prod): 
            ?>

            <div class="image">
                <img src="images/<?php $result = $SimpleUsers->prod($prod['pid']); foreach($result as $row):echo $row['product_img'];?>" alt=""  width="97px" height="110px"/>
            </div>
            <div class="name">
                    <?php echo $row['product'].' -- ';echo $prod['month']." mesi";?>
            </div>
                     <div class="price"> 
                <?php echo "N. licenze:".$prod['quantity'];?>
            </div>
            <div class="price">
                Price: <?php echo $row['price']*$prod['month']*$prod['quantity'];?>0€
            </div>

            <div class="btn">
                <form action='<?php echo $paypal_url; ?>' method='post' name='cart'>
                    <input type='hidden' name='business' value='<?php echo $paypal_id;?>'>
                    <input type='hidden' name='cmd' value='_cart'> 
                    <input type="hidden" name="upload" value="1">

                     <input type="hidden" name="quantity_<?php echo $i; ?>" value="<?php echo $prod['quantity']; ?>">
                    <input type='hidden' name='item_name_<?php echo $i; ?>' value='<?php echo $row['product'];?>'>
                    <input type='hidden' name='item_number_<?php echo $i; ?>' value='<?php echo $prod['pid'];?>'>
                    <input type='hidden' name='amount_<?php echo $i; ?>' value='<?php echo $row['price']*$prod['month'];endforeach; ?>'>
<?php $i++; ?>
                    <input type='hidden' name='no_shipping' value='1'>
                    <input type='hidden' name='currency_code' value='EUR'>
                    <input type='hidden' name='handling' value='0'>
                    <input type='hidden' name='cancel_return' value='http://www.example.com/paypal/cancel.php'>
                    <input type='hidden' name='return' value='http://www.example.com/paypal/success.php'>

            <?php

      endforeach;  
        ?>

但是在success.php页面上,我得到了所有变量,除了item_number是void

Success.php (我得到变量的部分)

$uid = $_SESSION['uid'];
$username=$_SESSION['username'];

$item_no = $_GET['item_number']; 
$item_transaction = $_GET['tx'];
$item_price = $_GET['amt'];
$item_currency = $_GET['cc'];

我如何获得item_number变量?

2 个答案:

答案 0 :(得分:2)

您必须使用输入名称中的数组来获取多个值

<input type='hidden' name='item_number[]' value='<?php echo $prod['pid'];?>'>

您可以使用

获取值
print_r($_GET['item_number']) //You will get a array of item number

答案 1 :(得分:0)

当你以表格形式命名时,你就是我们

'item_number_<?php echo $i; ?>' (which can look like "item_number_3")

但是当你尝试使用$ _GET ['item_number']

来调用它时

您必须按照命名方式调用$ _GET ['item_number_2']。

希望能为你阐明它。

编辑+++++++++++++++++++++++++++++

如果我是你,我会改变

<input type='hidden' name='item_number_<?php echo $i; ?>' value='<?php echo $prod['pid'];?>'>

<input type='hidden' name='item_number' value='<?php echo $prod['pid'];?>'>

你打电话给$ _GET ['item_number']应该可以正常工作。