Php 我在脚本中遇到此错误(语法错误意外T_ELSE)
关于paypal IPN,我的脚本有一些问题。 我使用PHPDesigner 7,它在第(88)行给我一个红色错误,我真的试着看看是否有一个大括号丢失了,或者是否有什么地方出错了,但似乎没有什么问题。hoveren PHPDesigner在第88行显示了我的确切位置(语法错误出乎意料) 任何帮助都将受到感谢 这是我的代码:Php 我在脚本中遇到此错误(语法错误意外T_ELSE),php,mysql,web,paypal-ipn,Php,Mysql,Web,Paypal Ipn,关于paypal IPN,我的脚本有一些问题。 我使用PHPDesigner 7,它在第(88)行给我一个红色错误,我真的试着看看是否有一个大括号丢失了,或者是否有什么地方出错了,但似乎没有什么问题。hoveren PHPDesigner在第88行显示了我的确切位置(语法错误出乎意料) 任何帮助都将受到感谢 这是我的代码: <?php // PHP 4.1 // read the post from PayPal system and add 'cmd' $req = 'cm
<?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);
?>
拆下第87行的闭合支架}
(85或86,如果您愿意)
这是假设您想要else if
而不是第88行的if
,else if(strcmp($res,“INVALID”)==0{
,问题是这个else不适合代码的其余部分
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);
?>
根据我的评论,您有n个额外的
,并且您的elseif
条件没有父if条件尝试将其放在您的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);
?>
如果代码缩进一致,则查找不匹配的括号会容易得多。如果没有任何父级如果它位于else
案例中,则会有一个额外的结尾
如果没有父级它位于else
案例中获取一个支持php的IDE来编辑您的代码它。。。他们会指出你缺少的括号在哪里