0

我正在尝试验证 Pay Pal 订阅 IPN 的 mc_gross 变量。

以下代码不断为我提供 amount_data 的“资源 id #12”值。我要验证的数字是用户付款时放在表中的 0.05。变量 $id 测试正确,数字 (0.05) 在 payment_amount 列中 - 所以我不知道为什么它不能执行此查询。我是 MYSQL 的新手,所以对于任何明显的错误,我深表歉意。

$payment_amount = mysql_real_escape_string($_POST['mc_gross']);
   $amount_data = mysql_query ("SELECT * FROM subscriber WHERE payment_amount = '$payment_amount' AND id = '$id' "); 
    if ($amount_data != $_POST['mc_gross']) {
        $errmsg .= "'mc_gross' does not match: ";
        $errmsg .= $_POST['mc_gross']."\n";
        file_put_contents(dirname(__FILE__).'/logs/ipn.log',"\n###AMOUNT Don't MATCH Amount in Database='$payment_amount' Amount in requested='$amount_data'for id '$id'###\n",FILE_APPEND); 
    }
4

2 回答 2

1

用于 mysql_fetch_row()获取 $amount_data.Mysql_query() 仅返回资源 id

$amount_data = mysql_query ("SELECT * FROM subscriber WHERE payment_amount = '$payment_amount' AND id = '$id' "); 
$row = mysql_fetch_row($amount_data);

echo $row[0]; 

检查链接http://php.net/manual/en/function.mysql-fetch-row.php

于 2012-09-25T14:45:05.743 回答
0

这是有效的:

$payment_amount = mysql_real_escape_string($_POST['mc_gross']);
    //$amount = mysql_query ("SELECT payment_amount FROM subscriber WHERE id = '$id'");
    $amount_data = mysql_query ("SELECT * FROM subscriber WHERE payment_amount = '$payment_amount' AND id = '$id' "); 
    $row = mysql_fetch_row($amount_data);
    if ($row[6] != $_POST['mc_gross']) {
        $errmsg .= "'mc_gross' does not match: ";
        $errmsg .= $_POST['mc_gross']."\n";
        file_put_contents(dirname(__FILE__).'/logs/ipn.log',"\n###AMOUNT Don't MATCH Amount in Database='$row[6]' Amount in requested='$payment_amount' for id '$id'###\n",FILE_APPEND); 
    }
于 2012-09-26T10:43:52.313 回答