我已经坚持了一整天了,这是我用过的最长时间的编码。请帮助我。
我有以下代码,它是用于验证数据库帐户的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();
答案 0 :(得分:0)
你不应该为状态而不是用户级别而烦恼吗?
if($user_level=='unverified')
应该是
if($active=='unverified')
答案 1 :(得分: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将不匹配未经验证,并将导致“电子邮件匹配,但用户未经验证”的日志