1

我正在尝试制作一个贝宝结帐按钮,该按钮不在回声内时工作正常,但是当我将按钮放在回声内时,因为我需要动态生成它,它在引用“paypal_items”时出现问题();" 功能,这是添加用户在其购物车中的所有商品的功能。该按钮有效,它重定向到贝宝网站,但它说没有项目(这让我相信 paypal_items() 没有到达。我尝试了一堆不同的语法,但我无法弄清楚任何事情我想知道这是否可能,因为它在一个形式内,而且在一个回声内。

在购物车()中发生了更多事情,我只是删除了其中的大部分,因为它似乎没有必要,它基本上收集了购物车中内容的会话数据,然后将其回显给买家查看。

function paypal_items() { //this function takes the cart and organizes all the variables in a way that paypal can read it (this function is called on in the paypal send form)
$num = 0;
foreach($_SESSION as $name => $value) {
    if ($value!=0) {
        if(substr($name, 0, 5)=='cart_') {
            $id = substr ($name, 5, strlen($name)-5);
            $get = mysql_query ('SELECT id, name, price FROM products WHERE id='.mysql_real_escape_string((int)$id));
            while ($get_row = mysql_fetch_assoc ($get)) {
                $num++;
                echo '<input type="hidden" name="item_number_'.$num.'" value="'.$id.'">'; //This num and number from database listing is flip flopped.
                echo '<input type="hidden" name="item_name_'.$num.'" value="'.$get_row['name'].'">';
                echo '<input type="hidden" name="amount_'.$num.'" value="'.$get_row['price'].'">';
                echo '<input type="hidden" name="shipping_'.$num.'" value="'.$get_row['shipping'].'">'; //Cost of Shipping first item.
                echo '<input type="hidden" name="shipping2_'.$num.'" value="'.$get_row['shipping'].'">'; //Cost of shipping two or more items is applied (shipping is multiplied depending on quantity)
                echo '<input type="hidden" name="quantity_'.$num.'" value="'.$value.'">';
            }
        }
    }
} 

}

function cart() {
    if ($total = 0) {
           // Empty Cart Alert..
    }

    else {
        echo '<div class="checkoutBtn">'.'<p>
              <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
                 <input type="hidden" name="cmd" value="_cart">
                 <input type="hidden" name="upload" value="1">
                 <input type="hidden" name="business" value="blah@blahblah.com">
                 <?php paypal_items(); ?>
                 <input type="hidden" name="currency_code" value="USD">
                 <input type="hidden" name="amount" value="echo number_format($total, 2);">
                 <input type="image" src="images/cartPage/checkoutBtn.gif" width="247" height="54" name="submit" alt="Secure Checkout With PayPal!">
              </form>
            </p>;'.'</div>'.
    }
}
4

2 回答 2

0

试试这种方式:

function cart() {
    if ($total = 0) {
           // Empty Cart Alert..
    }

    else {
        echo '<div class="checkoutBtn"><p>
              <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
                 <input type="hidden" name="cmd" value="_cart">
                 <input type="hidden" name="upload" value="1">
                 <input type="hidden" name="business" value="blah@blahblah.com">';
        paypal_items();
        echo '<input type="hidden" name="currency_code" value="USD">
                 <input type="hidden" name="amount" value="'.number_format($total, 2).'">
                 <input type="image" src="images/cartPage/checkoutBtn.gif" width="247" height="54" name="submit" alt="Secure Checkout With PayPal!">
              </form>
            </p></div>';
    }
}
于 2013-06-27T08:24:34.293 回答
0

嗯嗯 <?php tags are on the wrong place.

尝试这个:

     <?php
    function cart() {
if ($total = 0) {
          // Empty Cart Alert..
  }
else {
    echo '<div class="checkoutBtn">'.'<p>
          <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
             <input type="hidden" name="cmd" value="_cart">
             <input type="hidden" name="upload" value="1">
             <input type="hidden" name="business" value="blah@blahblah.com">
              paypal_items();
             <input type="hidden" name="currency_code" value="USD">
             <input type="hidden" name="amount" value="echo number_format($total, 2);">
             <input type="image" src="images/cartPage/checkoutBtn.gif" width="247" height="54" name="submit" alt="Secure Checkout With PayPal!">
          </form>
        </p>;'.'</div>'.
   }
}
?>
于 2013-06-27T08:38:47.063 回答