提交 PayPal 表格和同时更新数据库

发布于 2024-12-03 02:34:58 字数 2418 浏览 0 评论 0原文

如果我使用标准 PayPal 表单进行付款,我是否可以通过稍微更改代码以包含更新详细信息来同时更新我的​​数据库?

这是我想要使用的标准 PayPal 付款表格 - 将根据需要进行更改。

 <form action="https://www.paypal.com/cgi-bin/webscr" method="post" id="payPalForm">

 <input type="hidden" name="item_number" value="01 - General Payment to FreelanceSwitch.com">
 <input type="hidden" name="cmd" value="_xclick">
 <input type="hidden" name="no_note" value="1">
 <input type="hidden" name="business" value="[email protected]">
 <input type="hidden" name="currency_code" value="USD">
 <input type="hidden" name="return" value="http://freelanceswitch.com/payment-complete/">

 Item Details:<br /><input name="item_name" type="text" id="item_name"  size="45">
 <br /><br />
 Amount: <br /><input name="amount" type="text" id="amount" size="45">
 <br /><br />
 <input type="submit" name="Submit" value="Submit">

 </form>

这是我在页面中的更新代码:

 $editFormAction = $_SERVER['PHP_SELF'];
 if (isset($_SERVER['QUERY_STRING'])) {
   $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
 }

 if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form")) {
   $updateSQL = sprintf("UPDATE db SET payment_page_completed=%s WHERE id=%s",
                   GetSQLValueString($_POST['payment_page_completed'], "text"),
                   GetSQLValueString($_POST['id'], "int"));

   mysql_select_db($database_connAdmin, $connAdmin);
   $Result1 = mysql_query($updateSQL, $connAdmin) or die(mysql_error());

   //$updateGoTo = "confirmation"; WILL NEED TO CHANGE AS NEEDS TO GO TO PAYPAL


   if (isset($_SERVER['QUERY_STRING'])) {
     $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
     $updateGoTo .= $_SERVER['QUERY_STRING'];
   }
   header(sprintf("Location: %s", $updateGoTo));
 }

这是我当前的表格

 <form action="<?php echo $editFormAction; ?>" name="form" class="" id="form" method="POST" enctype="multipart/form-data">
 <input type="hidden" name="id" value="<?php echo $_SESSION['id']; ?>" readonly="readonly">
 <input type="hidden" name="payment_page_completed" value="yes" readonly="readonly">
 </form>

谢谢

If I use the standard PayPal form for payments can I also update my db at the same time, by changing the code slightly to include the update details?

This is the standard PayPal payment form I want to use - Will change as necessary..

 <form action="https://www.paypal.com/cgi-bin/webscr" method="post" id="payPalForm">

 <input type="hidden" name="item_number" value="01 - General Payment to FreelanceSwitch.com">
 <input type="hidden" name="cmd" value="_xclick">
 <input type="hidden" name="no_note" value="1">
 <input type="hidden" name="business" value="[email protected]">
 <input type="hidden" name="currency_code" value="USD">
 <input type="hidden" name="return" value="http://freelanceswitch.com/payment-complete/">

 Item Details:<br /><input name="item_name" type="text" id="item_name"  size="45">
 <br /><br />
 Amount: <br /><input name="amount" type="text" id="amount" size="45">
 <br /><br />
 <input type="submit" name="Submit" value="Submit">

 </form>

This is my update coding in my page:

 $editFormAction = $_SERVER['PHP_SELF'];
 if (isset($_SERVER['QUERY_STRING'])) {
   $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
 }

 if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form")) {
   $updateSQL = sprintf("UPDATE db SET payment_page_completed=%s WHERE id=%s",
                   GetSQLValueString($_POST['payment_page_completed'], "text"),
                   GetSQLValueString($_POST['id'], "int"));

   mysql_select_db($database_connAdmin, $connAdmin);
   $Result1 = mysql_query($updateSQL, $connAdmin) or die(mysql_error());

   //$updateGoTo = "confirmation"; WILL NEED TO CHANGE AS NEEDS TO GO TO PAYPAL


   if (isset($_SERVER['QUERY_STRING'])) {
     $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
     $updateGoTo .= $_SERVER['QUERY_STRING'];
   }
   header(sprintf("Location: %s", $updateGoTo));
 }

This is my current form

 <form action="<?php echo $editFormAction; ?>" name="form" class="" id="form" method="POST" enctype="multipart/form-data">
 <input type="hidden" name="id" value="<?php echo $_SESSION['id']; ?>" readonly="readonly">
 <input type="hidden" name="payment_page_completed" value="yes" readonly="readonly">
 </form>

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

淤浪 2024-12-10 02:34:58

是的,您可以通过两种方式完成此操作,即向两侧提交表单,在一张表单上提交两次,一次提交到 paypal,另一次提交到可以将其保存在数据库中的页面。

编辑1:

在您的表单中添加两个这样的提交:

<input type="submit" name="submit" class="btns" id="submit1" value="Save in DB" onclick="changeWhere('http://yourwebsite.com/savedata.php');" >

<input type="submit" name="submit" class="btns" id="submit2" value="Move to PayPal"
onclick="changeWhere('https://www.paypal.com/cgi-bin/webscr');" disabled="true">

并在您的脚本中添加以下内容:

<script type="text/javascript">

function changeWhere(place){

    document.form.action=place;   //use your forms name inplace of form

}

</script>

编辑2:

对两个表单操作使用单个提交

在您的表单中添加此内容:

<input type="button" value="Submit" onclick="submitTwice(this.form)">

并在脚本中添加此内容:

<script type="text/javascript">
 function submitTwice(form){
 form.action = 'https://www.paypal.com/cgi-bin/webscr';
 form.submit();
 form.action = 'savedata.php';
 form.submit();
}
</script>

它对我有用。 :-)

编辑 3:

savedata.php 可能包含类似的代码;

<?php
$item_name   = $_POST['item_name'];
$item_price  = $_POST['item_price'];
$item_number = $_POST['item_number'];

$sql="Insert into sales (name, price, number) values ('$item_name', '$item_price', '$item_number')";
$result=mysql_query($sql);
?>

希望这有帮助。

Yes you can do it in two ways by submitting form to two sides with two submits on one form, one to paypal and other to the page where you can save it in your db.

EDIT 1:

In your form add two submits like this:

<input type="submit" name="submit" class="btns" id="submit1" value="Save in DB" onclick="changeWhere('http://yourwebsite.com/savedata.php');" >

<input type="submit" name="submit" class="btns" id="submit2" value="Move to PayPal"
onclick="changeWhere('https://www.paypal.com/cgi-bin/webscr');" disabled="true">

and in your script add this:

<script type="text/javascript">

function changeWhere(place){

    document.form.action=place;   //use your forms name inplace of form

}

</script>

EDIT 2:

using single submit for two form actions

add this in your form:

<input type="button" value="Submit" onclick="submitTwice(this.form)">

and in script add this:

<script type="text/javascript">
 function submitTwice(form){
 form.action = 'https://www.paypal.com/cgi-bin/webscr';
 form.submit();
 form.action = 'savedata.php';
 form.submit();
}
</script>

It works for me. :-)

EDIT 3:

savedata.php may include code like;

<?php
$item_name   = $_POST['item_name'];
$item_price  = $_POST['item_price'];
$item_number = $_POST['item_number'];

$sql="Insert into sales (name, price, number) values ('$item_name', '$item_price', '$item_number')";
$result=mysql_query($sql);
?>

Hope this helps.

極樂鬼 2024-12-10 02:34:58

此处提出了相同的问题,应该可以为您提供所需的答案。如果您需要澄清,请发表评论。

要引用这个答案,它涉及向您的 PHP 提交数据,然后使用套接字请求将该数据发送到 PayPal:

function post($host, $path, $data) { 
$http_response = ''; 
$content_length = strlen($data); 
$fp = fsockopen($host, 80); 
fputs($fp, "POST $path HTTP/1.1\r\n"); 
fputs($fp, "Host: $host\r\n"); 
fputs($fp, "Content-Type: application/x-www-form-urlencoded\r\n"); 
fputs($fp, "Content-Length: $content_length\r\n"); 
fputs($fp, "Connection: close\r\n\r\n"); 
fputs($fp, $data); 
while (!feof($fp)) $http_response .= fgets($fp, 28); 
fclose($fp); 
return $http_response; 
}
$postdata = '?foo=bar'; 
foreach($_POST as $key => $val) $postdata .= '&'.$key.'='.$val;

重要说明:我从链接的线程中复制了该代码,因此请检查一下更多信息。另外,这将提交给您的 PHP。如果您希望用户实际查看 PayPal 页面,您需要将用户重定向到该 POST 请求。

此外,您似乎可能会受益于使用 PayPal 的即时付款通知功能。这实际上会回调您选择的包含所有付款信息的 URL。我发现本教程非常有帮助学习如何在 PHP 中执行此操作。

An identical question was posed here and should give you the answers you need. If you need clarification please comment.

To quote that answer, it involves submitting data to your PHP, then using a socket request to send that data to PayPal:

function post($host, $path, $data) { 
$http_response = ''; 
$content_length = strlen($data); 
$fp = fsockopen($host, 80); 
fputs($fp, "POST $path HTTP/1.1\r\n"); 
fputs($fp, "Host: $host\r\n"); 
fputs($fp, "Content-Type: application/x-www-form-urlencoded\r\n"); 
fputs($fp, "Content-Length: $content_length\r\n"); 
fputs($fp, "Connection: close\r\n\r\n"); 
fputs($fp, $data); 
while (!feof($fp)) $http_response .= fgets($fp, 28); 
fclose($fp); 
return $http_response; 
}
$postdata = '?foo=bar'; 
foreach($_POST as $key => $val) $postdata .= '&'.$key.'='.$val;

Important Notes: I copied that code from the thread I linked, so check it out for more information. Also, this will submit to your PHP. You'll need to redirect the user to that POST request if you want them to actually view the PayPal page.

Moreover, it seems like you might benefit from using PayPal's Instant Payment Notification feature. This essentially calls back a URL of your choosing with all of the payment information. I found this tutorial immensely helpful in learning how to do this in PHP.

昇り龍 2024-12-10 02:34:58

我有同样的问题,我所做的是执行 Ajax 暂停我的提交并调用我的 insert.php。我的 insert.php 几乎保存到数据库。我在这里写下了具体的步骤。 在重定向到 PayPal 之前将 HTML 表单 POST 保存到数据库

<script>

 $(function () {

        $('#senrollnow').on('submit', function (e) {

      var form = $(this);

      if(!form.hasClass('pending')) {

          e.preventDefault();

          form.addClass('pending');

          $.ajax({

              type: 'post',

              url: 'insert.php',

              data: $('#senrollnow').serialize(),

              success: function () {

                form.submit();

                 alert('form was submitted'+data);

              }
          });
      }
});

  $('#freeform').on('submit', function (e) {

  //e.preventDefault(); //prevents the form to submit

          alert("Your request has been sent! Please check your email within 12 hours for my feedback. Thank you.");

        });

      });

</script>

I have the same problem, what I did is to do Ajax pausing my submittion and calling my insert.php. My insert.php pretty much the saving to database. I have written the exact steps here. Save HTML form POST to database before redirecting to PayPal

<script>

 $(function () {

        $('#senrollnow').on('submit', function (e) {

      var form = $(this);

      if(!form.hasClass('pending')) {

          e.preventDefault();

          form.addClass('pending');

          $.ajax({

              type: 'post',

              url: 'insert.php',

              data: $('#senrollnow').serialize(),

              success: function () {

                form.submit();

                 alert('form was submitted'+data);

              }
          });
      }
});

  $('#freeform').on('submit', function (e) {

  //e.preventDefault(); //prevents the form to submit

          alert("Your request has been sent! Please check your email within 12 hours for my feedback. Thank you.");

        });

      });

</script>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文