我想做一個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>'.
}
}
您使用的回聲內標籤。刪除這些標籤,它應該工作 – Albzi