解析错误意外 } 在 if-else 块中



我已经在SO上搜索了一个多小时,但无法解决我的问题。由于某种原因,页面上有错误,因为第 262 行中的解析错误:语法错误意外 }。它是 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('abc@mail.com', 'ABC');
$mail->addAddress($to);
$mail->isHTML(true);
$mail->Subject = 'New Image Uploaded';
$mail->Body = $htmlContent;
$mail->send();
$mail->clearAddresses();
}

没有足够的点来评论,所以作为一个可能的答案:

当我的代码(像你的一样)很好时,我遇到了一连串神秘的"解析错误"。

就我而言,这是由我的 PC(操作系统/浏览器?)在从网页复制和粘贴示例代码期间以某种方式插入的虚假隐藏字符引起的。

例如 else {

如果"else"和"{"之间的"空格"

实际上不是"空格",那么它可能会导致后续{被忽略。结果:提前终止 else 语句即 else $htmlContent .= "<p>Hey,</p>";,其余的 conacateation 将被视为 else 块之外的语句,结束的 "}" 将被视为无效。

尝试删除 else 子句并手动重新键入。

如果这不起作用,请在编辑器集中打开您的代码以显示隐藏字符。 在HTML套件中(我认为),视图>编辑器>隐藏字符将显示此类字符为纯黑色,而不是纯白色的空间。