1

我已经坚持了一整天了,这是我一直坚持编码的时间最长的一次。请帮我。

我有以下代码,它是一个用于验证数据库帐户的 paypal ipn URL。我首先连接到 sql 等,然后从 paypal 获取用户信息,然后从数据库中获取用户信息。在付款之前,用户应该在 user_level 列中具有“未验证”的值,如果是“未验证”,则应该更新它。

这是我被困在的奇怪的事情。user_level 的值永远不会“未验证”,即使我在运行代码之前检查了实际的数据库,它实际上是“未验证的”。但是当我注释掉 mysql_query($u) 时,它给出的值是“未验证”。

正在发生的事情是,它似乎在调用实际代码以检查是否更新它之前更新记录。

请帮助任何人,我将不胜感激。我

$sql_connect = @mysql_connect($_SERVER['HTTP_HOST'].':3306','root', '******')   or  die('Could not connect: ' . mysql_error());
mysql_select_db('4bkk');

$url = 'https://www.sandbox.paypal.com/cgi-bin/webscr';

$postFields = 'cmd=_notify-validate';

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

$ch = curl_init();

curl_setopt_array($ch, array(
    CURLOPT_URL => $url,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_SSL_VERIFYPEER => false,
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => $postFields
));

$result = curl_exec($ch);
curl_close($ch);


if($result=='VERIFIED'){

$log = 'Verfied --- ';

    //get buyers information from PAYPAL checkout
    $email = $_POST['payer_email'];
    $first_name = $_POST['first_name'];
    $last_name = $_POST['last_name'];
    $amount = $_POST['amount3'];
    $plan = $_POST['option_selection1'];

    $q = "SELECT * FROM users WHERE email='$email'";
    $data = mysql_query($q);

    $con = mysql_fetch_array($data); 

    //get buyers information from DATABASE
    $email2 = $con['email'];
    $first_name = $con['first_name'];
    $last_name = $con['last_name'];
    $active = $con['active'];
    $user_level = $con['user_level'];

$log .= $first_name.' ,  '.$last_name.' ,  '.$email2.' ,  '.$active.' ,  '.$user_level.' **************** '.$email ;

if($email2==$email){ //User already has a record 
    if($user_level=='unverified'){ // User unverified, ready for verification
        $log .= 'Emails match, and user is VERIFIED';
        $u = "UPDATE users SET active='verified', user_level='$plan' WHERE email='$email' LIMIT 1";
        $log .= $u;

        mysql_query($u);

    }
    else{ // User is already verified, 
$log .= 'Emails match, BUT user is NOT VERIFIED';


    }
}
else{  //User doesn't have a record
    $log .= 'Emails DONT match, execute update here';
}

$fh = fopen('result_ipn_test.txt', 'w');
//fwrite($fh, $subject.' --- '.$message);
fwrite($fh, $message.' ********** '.$log);
fclose($fh);

}
else
    echo 'INVALID';


mysql_close();
4

2 回答 2

0

您不应该检查状态而不是用户级别吗?

if($user_level=='unverified')

应该

if($active=='unverified')
于 2012-10-31T16:13:48.283 回答
0

您正在检查用户是否未在数据库中验证,然后立即记录该用户已验证。此外,如果这不是检查 $active 而不是 $user_level,因为您将 $plan 的值放入 $user_level

if($user_level=='unverified'){ // User unverified, ready for verification
    $log .= 'Emails match, and user is VERIFIED';

同样,如果用户在数据库中被列为“已验证”,则您正在记录他未经过验证:

else{ // User is already verified, 
    $log .= 'Emails match, BUT user is NOT VERIFIED';

注释掉 sql 查询会导致 $data 为空,从而使 $user_level 为空。$user_level 将不匹配未验证并会导致日志“电子邮件匹配,但用户未验证”

于 2012-10-31T16:17:21.407 回答