2013-07-16 67 views
-1

我的腳本有關於貝寶IPN的一些問題。 我使用PHPDesigner 7,它給我一個線(88)上的紅色錯誤,我真的試圖看看是否有一個大括號丟失或者是否有錯誤,但沒有什麼看起來錯誤hoveren PHPDesigner完全顯示我在第88行(語法錯誤意外的T_ELSE)。我得到這個錯誤在我的腳本(語法錯誤意外T_ELSE)

任何幫助表示感謝提前。

這是我的代碼:

<?php 

// PHP 4.1 

// read the post from PayPal system and add 'cmd' 

$req = 'cmd=_notify-validate'; 

$File = "errorss.txt"; 
$Handle = fopen($File, 'w'); 
$Data = "Entered the IPN script\n"; 
fwrite($Handle, $Data); 

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

// post back to PayPal system to validate 
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n"; 
$header .= "Content-Type: application/x-www-form-urlencoded\r\n"; 
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n"; 
$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30); 

$Data = "Authentication Complete\n"; 
fwrite($Handle, $Data); 

// 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']; 
$payment_gross = $_POST['payment_gross']; 
$payment_fee = $_POST['payment_fee']; 

$Data = "Iten number:".$item_number." ".$payment_status."\n"; 
fwrite($Handle, $Data); 

if (!$fp) { 


$Data = "Error\n"; 
fwrite($Handle, $Data); 

} else { 
fputs ($fp, $header . $req); 
while (!feof($fp)) { 
$res = fgets ($fp, 1024); 
if (strcmp ($res, "VERIFIED") == 0) { 

$Data = "Verified\n"; 
fwrite($Handle, $Data); 
    if($payment_status == "Completed") 
    { 

$Data = "Completed\n"; 
fwrite($Handle, $Data); 

require_once('./dbconnect.php'); 



$kkql= mysql_query("SELECT * FROM orders WHERE w='$item_number'"); 



       if(mysql_num_rows($kkql) == 0) 
        { 

        exit(); 
        } 

           mysql_query("UPDATE orders SET paid='1'"); 







       } 
    } 
} 
else if (strcmp ($res, "INVALID") == 0) { 
// log for manual investigation 
} 

} 
fclose ($fp); 


} //This is also causing the error i think as it is red when it click on it, open and closed braces are displayed in green this one in red 
fclose($Handle); 
?> 
+2

查找不匹配支架多,如果您始終縮進代碼,則會更容易。 – andrewsi

+1

你有一個額外的關閉''' –

+0

你的'else if'沒有任何父'if'它在'else'情況 –

回答

0

卸下右括號,},上線87(85或86,如果你喜歡)。

這是假設你想要else if而不是if在線88,else if (strcmp ($res, "INVALID") == 0) {

0

的問題是,這個別人也不適合與代碼

else if (strcmp ($res, "INVALID") == 0) { 
    // log for manual investigation 
} 

的其餘部分我想你大概意思是這樣的

<?php 

// PHP 4.1 

// read the post from PayPal system and add 'cmd' 

$req = 'cmd=_notify-validate'; 

$File = "errorss.txt"; 
$Handle = fopen($File, 'w'); 
$Data = "Entered the IPN script\n"; 
fwrite($Handle, $Data); 

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

// post back to PayPal system to validate 
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n"; 
$header .= "Content-Type: application/x-www-form-urlencoded\r\n"; 
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n"; 
$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30); 

$Data = "Authentication Complete\n"; 
fwrite($Handle, $Data); 

// 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']; 
$payment_gross = $_POST['payment_gross']; 
$payment_fee = $_POST['payment_fee']; 

$Data = "Iten number:".$item_number." ".$payment_status."\n"; 
fwrite($Handle, $Data); 

if (!$fp) { 
$Data = "Error\n"; 
fwrite($Handle, $Data); 
} else { 
    fputs ($fp, $header . $req); 
    while (!feof($fp)) { 
     $res = fgets ($fp, 1024); 
     if (strcmp ($res, "VERIFIED") == 0) { 
      $Data = "Verified\n"; 
      fwrite($Handle, $Data); 
      if($payment_status == "Completed") 
      { 
       $Data = "Completed\n"; 
       fwrite($Handle, $Data); 
       require_once('./dbconnect.php'); 
       $kkql= mysql_query("SELECT * FROM orders WHERE w='$item_number'"); 
       if(mysql_num_rows($kkql) == 0) 
       { 
        exit(); 
       } 
       mysql_query("UPDATE orders SET paid='1'"); 
      } 
     } 
     if (strcmp ($res, "INVALID") == 0) { 
      // log for manual investigation 
     } 
    } 
} 
    fclose ($fp); 
} //This is also causing the error i think as it is red when it click on it, open and closed braces are displayed in green this one in red 
fclose($Handle); 
?> 

如果您縮進代碼好聽它犯錯這很明顯。

0

按我的意見,你有n個額外}和你elseif條件是不父,如果條件儘量把你的if後,取下最後收}

<?php 

// PHP 4.1 

// read the post from PayPal system and add 'cmd' 

$req = 'cmd=_notify-validate'; 

$File = "errorss.txt"; 
$Handle = fopen($File, 'w'); 
$Data = "Entered the IPN script\n"; 
fwrite($Handle, $Data); 

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

// post back to PayPal system to validate 
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n"; 
$header .= "Content-Type: application/x-www-form-urlencoded\r\n"; 
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n"; 
$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30); 

$Data = "Authentication Complete\n"; 
fwrite($Handle, $Data); 

// 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']; 
$payment_gross = $_POST['payment_gross']; 
$payment_fee = $_POST['payment_fee']; 

$Data = "Iten number:".$item_number." ".$payment_status."\n"; 
fwrite($Handle, $Data); 

if (!$fp) { 


$Data = "Error\n"; 
fwrite($Handle, $Data); 

} else { 
fputs ($fp, $header . $req); 
while (!feof($fp)) { 
$res = fgets ($fp, 1024); 
if (strcmp ($res, "VERIFIED") == 0) { 

$Data = "Verified\n"; 
fwrite($Handle, $Data); 
if($payment_status == "Completed") 
{ 

$Data = "Completed\n"; 
fwrite($Handle, $Data); 

require_once('./dbconnect.php'); 



$kkql= mysql_query("SELECT * FROM orders WHERE w='$item_number'"); 



      if(mysql_num_rows($kkql) == 0) 
       { 

       exit(); 
       } 

          mysql_query("UPDATE orders SET paid='1'"); 







      } 
}else if (strcmp ($res, "INVALID") == 0) { 
// log for manual investigation 
} 
} 



fclose ($fp); 


} //This is also causing the error i think as it is red when it click on it, open and closed braces are displayed in green this one in red 
fclose($Handle); 
?> 
相關問題