2013-06-27 19 views
1

我想做一個PayPal結帳按鈕,該按鈕工作正常時,它不是在一個回聲裏面,但當我把按鈕裏面的回聲,因爲我需要它動態地產生,它有一個問題引用「paypal_items();」功能,這是用戶在購物車中添加的所有項目的功能。該按鈕的作品,它重定向到貝寶網站,但它說沒有項目(這使我相信paypal_items()沒有達到。我已經嘗試了一堆不同的語法,但我無法找出任何東西我想知道這是否甚至可能,因爲它在一個窗體裏面還有一個回聲你怎麼能把一個php函數內部的PHP回聲內的HTML表單內?

在cart()中發生了很多事情,我只是刪除了它的大部分,因爲它似乎沒有必要,它基本上收集的會話數據是什麼車,然後Echo的它爲買家看到。

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="[email protected]"> 
       <?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>'. 
    } 
} 
+0

您使用的回聲內標籤。刪除這些標籤,它應該工作 – Albzi

回答

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="[email protected]">'; 
     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>'; 
    } 
} 
+0

這工作完美,輝煌,非常感謝你! –

0

Euhm的<?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="[email protected]"> 
       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>'. 
    } 
} 
?> 
+1

感謝您的評論,我已經嘗試過,沒有運氣。我認爲問題在於paypal_items是ECHO內部的ECHOING ....所以它的兩次輸出只是不起作用?我需要做下面你說的那個人,把回聲分解成兩個回聲,然後讓這個功能坐在中間。 –