当我从购物车中点击paypal立即购买按钮时,如何将数据提交到我的数据库

时间:2012-03-22 18:44:53

标签: php paypal-ipn

您好我创建了一个Paypal IPN,我的购物车页面中有一个现在付费按钮,这是一个图像类型。我习惯使用提交类型。我只是想知道如何写我的数据库关于这个现在付费按钮的提交。我的意思是我想写入数据库,因为单击此按钮但我不确定如何做到这一点?这是我将数据发送到PayPal的代码。

<?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:  &euro;" .$_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>

2 个答案:

答案 0 :(得分:1)

在前往PayPal之前,您需要添加一个步骤。基本上你的购物车会POST到你网站上的另一个脚本,它会记录你需要的任何信息,然后你可以循环浏览你的购物车并通过URL上的GET字符串发送给PayPal。我相信变量是相同的,而且你甚至可以事先得到他们的名字和地址信息。

答案 1 :(得分:0)

您总是可以使用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>

干杯。 ;)

相关问题