Php Paypal sandbox IPN未更新我的数据库表

Php Paypal sandbox IPN未更新我的数据库表,php,paypal,Php,Paypal,我做了贝宝IPN,但我没有得到任何在我的数据库。这是我的按钮(我让它再次出现)和我的代码,有人看到我哪里出错了吗?任何人都可以帮我解决这个问题 <?php $conn = mysql_connect('localhost', 'USERNAME', 'PASSWORD'); if(!$conn) { die("Could not connect: ".mysql_error()); } $database = mysql_select_db('fbkidsonlinedb', $conn

我做了贝宝IPN,但我没有得到任何在我的数据库。这是我的按钮(我让它再次出现)和我的代码,有人看到我哪里出错了吗?任何人都可以帮我解决这个问题

<?php
$conn = mysql_connect('localhost', 'USERNAME', 'PASSWORD');
if(!$conn) { die("Could not connect: ".mysql_error()); }

$database = mysql_select_db('fbkidsonlinedb', $conn);
if(!$database) { die("Can't use database: ".mysql_error()); }


// 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";
}

// If testing on Sandbox use: 
$header .= "Host: <!-- w --><a class="postlink" href="http://www.sandbox.paypal.com:443">www.sandbox.paypal.com:443</a><!-- w -->\r\n";
//$header .= "Host: <!-- w --><a class="postlink" href="http://www.paypal.com:443">www.paypal.com:443</a><!-- w -->\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";

// If testing on Sandbox use:
$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
//$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 = mysql_real_escape_string($_POST["custom"]);

if (!$fp) {
    // HTTP ERROR
} else {
    fputs ($fp, $header . $req);
    while (!feof($fp)) {
        $res = fgets ($fp, 1024);
        if (strcmp ($res, "VERIFIED") == 0) {
            if ($payment_status=='Completed') {
                $txn_id_check = mysql_query("SELECT txn_id FROM log WHERE txn_id =".$txn_id."");
                if (mysql_num_rows($txn_id_check) !=1) {
                    if ($payment_amount=='29.95' && $payment_currency=='USD') {
                        $log_query = mysql_query("INSERT INTO log VALUES ('', '".$txn_id."', '".$payer_email."')");
                        $update_premium = mysql_query("UPDATE users SET authLevel='1' where fbID='".$user_id."'");
                    }
                }
            }
        }
        else if (strcmp ($res, "INVALID") == 0) {
            // log for manual investigation
        }
    }
    fclose ($fp);
}

为什么要为主机分配链接:

$header .= "Host: <!-- w --><a class="postlink" href="http://www.sandbox.paypal.com:443">www.sandbox.paypal.com:443</a><!-- w -->\r\n";

无论如何,我对PayPal不太熟悉,如果这是我的错误,那么很抱歉,

为什么要为主机分配链接:

$header .= "Host: <!-- w --><a class="postlink" href="http://www.sandbox.paypal.com:443">www.sandbox.paypal.com:443</a><!-- w -->\r\n";

无论如何,我对PayPal不太熟悉,如果是我的错误,很抱歉

您需要验证是否有数据进入,因此请查看
print\r($\u POST)
显示的内容。您正在运行大量查询,但没有任何错误检查,因此您不会看到出现了什么问题。你确定首先调用了正确的脚本吗?@sindu-首先你确定你得到了IPN吗?你需要验证是否确实有数据进入,所以看看
print\r($\u POST)
显示了什么。你正在运行大量的查询,没有任何错误检查,所以你不会看到哪里出了问题。你确定一开始就调用了正确的脚本吗?@sindu-首先你确定你得到了IPN吗?
$header .= "Host:http://www.sandbox.paypal.com:443\r\n";