提交 PayPal 表格和同时更新数据库
如果我使用标准 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,您可以通过两种方式完成此操作,即向两侧提交表单,在一张表单上提交两次,一次提交到 paypal,另一次提交到可以将其保存在数据库中的页面。
编辑1:
在您的表单中添加两个这样的提交:
并在您的脚本中添加以下内容:
编辑2:
对两个表单操作使用单个提交
在您的表单中添加此内容:
并在脚本中添加此内容:
它对我有用。 :-)
编辑 3:
savedata.php 可能包含类似的代码;
希望这有帮助。
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:
and in your script add this:
EDIT 2:
using single submit for two form actions
add this in your form:
and in script add this:
It works for me. :-)
EDIT 3:
savedata.php may include code like;
Hope this helps.
此处提出了相同的问题,应该可以为您提供所需的答案。如果您需要澄清,请发表评论。
要引用这个答案,它涉及向您的 PHP 提交数据,然后使用套接字请求将该数据发送到 PayPal:
重要说明:我从链接的线程中复制了该代码,因此请检查一下更多信息。另外,这将提交给您的 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:
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.
我有同样的问题,我所做的是执行 Ajax 暂停我的提交并调用我的 insert.php。我的 insert.php 几乎保存到数据库。我在这里写下了具体的步骤。 在重定向到 PayPal 之前将 HTML 表单 POST 保存到数据库
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