嗨,我正在创建一个Paypal IPN,我的购物车页面中有一个立即付款按钮,它是image类型的。我习惯于使用提交类型。我只是想知道如何在这个立即付款按钮的子菜单上写入我的数据库。我的意思是,当点击这个按钮时,我想写入数据库,但我不确定该怎么做?这是我将数据发送到贝宝的代码。
<?php
if(isset($_SESSION['username']) && isset($_SESSION['itemnames']))
{
$checkoutbutton .='<form action="https://www.sandbox.paypal.com/cgibin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="business" value="xxxxxx">
<input type="hidden" name="upload" value="1">';
?> <ul2>
<?php
for ($i = 0;$i <count($_SESSION['itemnames']);$i++)
{ ?>
<li>
<?php
$x = $i + 1;
echo "<h3>";
echo $_SESSION['itemnames'][$i];
echo "</h3>";
echo "<b>Cost per Item: €" .$_SESSION['price'][$i] ."</br> Number of Items: " . $_SESSION['quantity'][$i] ."</b>";
$checkoutbutton .='<input type="hidden" name="item_name_'.$x.'" value="'. $_SESSION['itemnames'][$i] .'">
<input type="hidden" name="amount_'.$x.'" value="' .$_SESSION['price'][$i] . '">
<input type="hidden" name="quantity_'.$x.'" value="' .$_SESSION['quantity'][$i] . '">';
?>
</li>
<?php } $checkoutbutton .='<input type="hidden" name="notify_url" value="http://ipnscript.php">
<input type="hidden" name="return" value="http://ranscomplete.php">
<input type="hidden" name="rm" value="2">
<input type="hidden" name="cbt" value="return to store">
<input type="hidden" name="cancel_return" value="http://www.theislandapp.com/transcancelled.php">
<input type="hidden" name="currency_code" value="EUR">
<input type="image" src="x-click-but5.gif" name="submit" alt="Make payments with PayPal - its fast, free and secure!">';
?>
</ul2>
<?php }
else {?>
<h2> No Items in cart </h2>
<?php } ?> </br></br>
在前往PayPal之前,您需要添加一个步骤。基本上,你的购物车会在你的网站上发布到另一个脚本,该脚本会记录你需要的任何信息,然后你可以在购物车中循环,并通过URL上的GET字符串将东西发送到PayPal。我相信这些变量是一样的,而且你甚至可以事先获得他们的姓名和地址信息存储在你身边。
您可以始终使用ajax(jquery)在后台调用页面,它甚至不必显示任何数据。
$.post("save.php", { name: "John", item: "143" } );
http://api.jquery.com/jQuery.post/
通过给你的购买按钮一个id,并使用点击功能可以实现这一点。
<input id="yebeclicked" type="image" src="x-click-but5.gif" name="submit" alt="Make payments with PayPal - its fast, free and secure!">
<script type="text/javascript">
$("#yebeclicked").click(function() {
$.post("save.php", { name: "John", item: "143" } );
});
</script>
干杯。)