dongshui2254 2013-04-17 17:15
浏览 28

IPN脚本不更新MYSQL数据库

I'm trying to get a ipn script working so that I can integrate Paypal into my site.

Once the purchase is complete, I'm aiming for the script to update 3 MYSQL values, the premium value (needs to update to 1 to show the user is premium), and then the start and end date for the registration.

However, when I test, the database does not update. Nor do any errors echo out.

Heres the databse updating part of the code:

//update premium to 1    
$query = sprintf("UPDATE `users` SET `premium` = '1' WHERE `user_id` = '".$user_id."'");
mysql_query($query)or die('Could not update premium status: ' . mysql_error());

//update startdate to current date
$query = sprintf("UPDATE `users` SET `startdate` = '$startdate1' WHERE `user_id` = '".$user_id."'");
mysql_query($query)or die('Could not update licence date details (1): ' . mysql_error());

//update enddate to current date +365 days
$query = sprintf("UPDATE `users` SET `enddate` = '$enddate1' WHERE `user_id` = '".$user_id."'");
mysql_query($query)or die('Could not update licence date details (2): ' . mysql_error());

Heres the full ipn code:

    <pre class="php"><?php
require 'glob.inc.php';

$posted_data = print_r($_POST,true);
file_put_contents('IPN_data.txt',$posted_data);

// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';

foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}

// post back to PayPal system to validate
$header .= "POST /cgi-bin/webscr HTTP/1.0
";
$header .= "Content-Type: application/x-www-form-urlencoded
";
$header .= "Content-Length: " . strlen($req) . "

";
$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);

// assign posted variables to local variables
$item_name = $_POST["item_name"];
$item_number = $_POST["item_number"];
$payment_status = $_POST["payment_status"];
$payment_amount = $_POST["mc_gross"];
$payment_currency = $_POST["mc_currency"];
$txn_id = $_POST["txn_id"];
$receiver_email = $_POST["receiver_email"];
$payer_email = $_POST["payer_email"];
$user_id = $_POST["custom"]; //our users id.

if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {

        if ($_POST['payment_status'] == 'completed')
{ 

//values for date info

$startdate1 = date("Y-m-d");
$enddate1 = date("Y-m-d", strtotime("+ 365 day"));

//update whatever information you need to               
// update premium to 1

                                            $query = sprintf("UPDATE `users` SET `premium` = '1' WHERE `user_id` = '".$user_id."'");

                                              mysql_query($query)or die('Could not update premium status: ' . mysql_error());

                                              //update startdate to current date

                                                $query = sprintf("UPDATE `users` SET `startdate` = '$startdate1' WHERE `user_id` = '".$user_id."'");

                                              mysql_query($query)or die('Could not update licence date details (1): ' . mysql_error());

                                              //update enddate to current date +365 days

                                               $query = sprintf("UPDATE `users` SET `enddate` = '$enddate1' WHERE `user_id` = '".$user_id."'");

                                              mysql_query($query)or die('Could not update licence date details (2): ' . mysql_error());

}
}
else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation
}
}
fclose ($fp);
}
?></pre>

I know im working with depreciated MYSQL, but I have to for this project. Just have to go with me on that one. Im also a beginner, so am learning as I go. the script connects to the database via glob.inc.php, which is required at the start of the ipn script.

I've looked at the IPN data report from Paypal, and the correct user ID (custom field) is being sent and returned. The database does not update though...

Any ideas?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Centos7 / PETGEM
    • ¥15 csmar数据进行spss描述性统计分析
    • ¥15 各位请问平行检验趋势图这样要怎么调整?说标准差差异太大了
    • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
    • ¥15 wpf界面一直接收PLC给过来的信号,导致UI界面操作起来会卡顿
    • ¥15 init i2c:2 freq:100000[MAIXPY]: find ov2640[MAIXPY]: find ov sensor是main文件哪里有问题吗
    • ¥15 运动想象脑电信号数据集.vhdr
    • ¥15 三因素重复测量数据R语句编写,不存在交互作用
    • ¥15 微信会员卡等级和折扣规则
    • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗