我已经坚持了一整天了,这是我一直坚持编码的时间最长的一次。请帮我。
我有以下代码,它是一个用于验证数据库帐户的 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();