2017-10-06 174 views
0

我一直在SO上搜索了一个多小时,但无法解决我的问题。出于某种原因,在页面上出现错误:解析错误:语法错误意外}在行262.它是关闭其他条件的括号。解析错误意外}在if-else块

我删除了其他条件,代码运行顺利。然后我恢复并删除了其他条件内的所有内容,但仍然出现错误,我很困惑为什么结尾括号是意外的。

下面是代码

if(isset($_POST['sendEmailNotification'])){ 

$keyword = $_POST['sendEmailNotification']; 
$sql = "SELECT * FROM team where keyword = '$keyword'" ; 
$sql_result = mysqli_query($conn,$sql) or die (mysqli_error($conn)); 
while ($row = mysqli_fetch_assoc($sql_result)){ 
    $abcd = $row; 
} 

$htmlContent = file_get_contents ("email_template_header.php"); 
$registerURL = $siteURL.'/register/'; 

if ($abcd['claimed'] == 1) { 

    $htmlContent .= "<p>Hey,</p>"; 
    $htmlContent .= "<p>Hope you're doing well!!!</p>"; 
    $htmlContent .= "<p>Someone has submitted an image related to your business on www.trustedbusiness.reviews. He/She might be your customer or may be your employee/ex-employee.</p>"; 
    $htmlContent .= "<p>You can approve the image just by following these simple steps:</p>"; 
    $htmlContent .= "<ol>"; 
    $htmlContent .= "<li>View Business Center</li>"; 
    $htmlContent .= "<li>Click on Business Name</li>"; 
    $htmlContent .= "<li>Select 'Image' option from sidebar</li>"; 
    $htmlContent .= "<li>Approve the 'Image' & you're done</li>"; 
    $htmlContent .= "</ol>"; 
    $htmlContent .= "<p>If you need any help or have any suggestions to make the User Experience better. Please feel free to contact Trusted Business Reviews team.</p>"; 
    $htmlContent .= "<p>Thanks</p>"; 

} 
else { 

    $htmlContent .= "<p>Hey,</p>"; 
    $htmlContent .= "<p>Hope you're doing well!!!</p>"; 
    $htmlContent .= "<p>Someone has submitted an image related to your business on www.trustedbusiness.reviews. He/She might be your customer or maybe your employee/ex-employee.</p>"; 
    $htmlContent .= "<p>Uh-oh!</p>"; 
    $htmlContent .= "<p>You haven't claimed your business on Trusted Business Reviews? No problem!</p>"; 
    $htmlContent .= "<p>You can claim this by following these simple & super easy steps:</p>"; 
    $htmlContent .= "<ol>"; 
    $htmlContent .= "<li>Register here</li>"; 
    $htmlContent .= "<li>Open your Business Listing Page</li>"; 
    $htmlContent .= "<li>Click on 'Claim This Business'</li>"; 
    $htmlContent .= "<li>Enter your domain email address</li>"; 
    $htmlContent .= "<li>Enter Verification Code</li>"; 
    $htmlContent .= "<li>You're Done</li>"; 

    $htmlContent .= "</ol>"; 
    $htmlContent .= "<p>You can make the desired changes in the information (if needed) after 'claim this business' process.</p>"; 
    $htmlContent .= "<p>Later, You can approve the image just by following these simple steps:</p>"; 
    $htmlContent .= "<ol>"; 
    $htmlContent .= "<li>View Business Center</li>"; 
    $htmlContent .= "<li>Click on Business Name</li>"; 
    $htmlContent .= "<li>Select 'Image' option from sidebar</li>"; 
    $htmlContent .= "<li>Approve the 'Image' & you're done</li>"; 
    $htmlContent .= "</ol>"; 
    $htmlContent .= "<p>If you need any help or have any suggestions to make the User Experience better. Please feel free to contact Trusted Business Reviews team.</p>"; 
    $htmlContent .= "<p>Thanks</p>"; 
} 
$htmlContent .= file_get_contents ("email_template_footer.php"); 
$to = $abcd['b_email']; 

require 'PHPMailerAutoload.php'; 

$mail = new PHPMailer; 
$mail->isSMTP(); 
$mail->Host = 'localhost'; 
$mail->SMTPAuth = false; 
$mail->SMTPSecure = 'tls'; 
$mail->Port = 25; 
$mail->setFrom('[email protected]', 'ABC'); 
$mail->addAddress($to); 
$mail->isHTML(true); 
$mail->Subject = 'New Image Uploaded'; 
$mail->Body = $htmlContent; 
$mail->send(); 
$mail->clearAddresses(); 
} 
+0

您发布的代码不会生成解析错误,因此问题必须在其他位置。 – jeroen

+0

奇怪......我看到它正好在我的前面.. –

+0

对于像括号这样的语法错误,并不总是那个行号是相同的。它必须在某个地方突破这个代码。 –

回答

2

没有足够的点评论,以便作为一个可能的答案进行:

我有一个神秘的一连串“解析错误”时,我的代码(像你这样)的罚款。

在我的情况下,它是由我的电脑(操作系统/浏览器?)插入伪造的隐藏字符引起的,它是在复制和粘贴来自网页的示例代码期间引起的。

例如else {

如果“else”和“{”之间的“空格”实际上不是“空格”,则可能会导致后续{被忽略。结果:else语句 (即else $htmlContent .= "<p>Hey,</p>";)的提前终止,您的共部分的其余部分将被视为else语句之外的语句,并且关闭“}”为无效。

尝试删除您的else子句并手动重​​新输入。

如果这不起作用,请在编辑器中打开您的代码以显示隐藏的字符。在HTML工具包中(我认为)view-> editor->隐藏字符将显示诸如纯黑色之类的字符,而不是纯白色的空格。

+0

你是对的,有一些看不见的字符附近的括号。我删除了它们,它像魅力一样工作。 –