提交贝宝(PayPal)表格和同时更新数据库 [英] Submit PayPal form & Update Database at same time

查看:76
本文介绍了提交贝宝(PayPal)表格和同时更新数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?

这是我要使用的标准PayPal付款表单-会根据需要进行更改.

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="your@paypalaccount.com">
 <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));
 }

这是我当前的表格

 <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>

谢谢

推荐答案

是的,您可以通过两种方式来完成此任务:将表单提交到两侧,一次提交两次,一种提交到Paypal,另一种提交到您可以保存的页面它在您的数据库中.

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.

在您的表单中添加两个提交,如下所示:

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>

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

using single submit for two form actions

以您的形式添加它:

<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>

对我有用. :-)

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

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);
?>

希望这会有所帮助.

这篇关于提交贝宝(PayPal)表格和同时更新数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆