在 if-else 块中解析错误 Unexpected } [英] Parse error Unexpected } in if-else block

查看:185
本文介绍了在 if-else 块中解析错误 Unexpected }的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 SO 上搜索了一个多小时,但未能解决我的问题.由于某种原因,第 262 行的页面上出现了 Parse Error: syntax error unexpected } 错误.它是 else 条件的右括号.

我删除了 else 条件,代码运行顺利.然后我恢复并删除了 else 条件中的所有内容,但错误仍然相同,我很困惑为什么右括号是意外的.

这是代码

if(isset($_POST['sendEmailNotification'])){$keyword = $_POST['sendEmailNotification'];$sql = "SELECT * FROM team where keyword = '$keyword'" ;$sql_result = mysqli_query($conn,$sql) 要么死 (mysqli_error($conn));而 ($row = mysqli_fetch_assoc($sql_result)){$abcd = $row;}$htmlContent = file_get_contents("email_template_header.php");$registerURL = $siteURL.'/register/';如果 ($abcd['声称'] == 1) {$htmlContent .= "<p>嘿,</p>";$htmlContent .= "<p>希望你一切顺利!!!</p>";$htmlContent .= "<p>有人在 www.trustedbusiness.reviews 上提交了与您的业务相关的图片.他/她可能是您的客户,也可能是您的员工/前雇员.</p>";$htmlContent .= "

您只需按照以下简单步骤即可批准图片:</p>";$htmlContent .="

    ";$htmlContent .="
  1. 查看商务中心
  2. ";$htmlContent .= "
  3. 点击商家名称
  4. ";$htmlContent .= "
  5. 从侧边栏中选择'图片'选项
  6. ";$htmlContent .= "<li>批准‘图片’&你已经完成了</li>";$htmlContent .= "</ol>";$htmlContent .= "<p>如果您需要任何帮助或有任何建议以改善用户体验.请随时联系可信商业评论团队.</p>";$htmlContent .= "<p>谢谢</p>";}别的 {$htmlContent .= "<p>嘿,</p>";$htmlContent .= "<p>希望你一切顺利!!!</p>";$htmlContent .= "<p>有人在 www.trustedbusiness.reviews 上提交了与您的业务相关的图片.他/她可能是您的客户,也可能是您的员工/前雇员.</p>";$htmlContent .= "<p>Uh-oh!</p>";$htmlContent .= "<p>您还没有在 Trusted Business Reviews 上声明您的业务?没问题!</p>";$htmlContent .= "<p>您可以按照以下简单且超级简单的步骤声明此内容:</p>";$htmlContent .="

      ";$htmlContent .= "
    1. 在这里注册
    2. ";$htmlContent .= "
    3. 打开您的企业列表页面
    4. ";$htmlContent .= "
    5. 点击'声明此商家'
    6. ";$htmlContent .="
    7. 请输入您的域电子邮件地址
    8. ";$htmlContent .="
    9. 输入验证码
    10. ";$htmlContent .= "
    11. 你完成了
    12. ";$htmlContent .= "</ol>";$htmlContent .= "<p>您可以在声明此业务"流程之后对信息进行所需的更改(如果需要).</p>";$htmlContent .= "<p>稍后,您可以通过以下简单步骤批准图像:</p>";$htmlContent .="

        ";$htmlContent .="
      1. 查看商务中心
      2. ";$htmlContent .= "
      3. 点击商家名称
      4. ";$htmlContent .= "
      5. 从侧边栏中选择'图片'选项
      6. ";$htmlContent .= "<li>批准‘图片’&你已经完成了</li>";$htmlContent .= "</ol>";$htmlContent .= "<p>如果您需要任何帮助或有任何建议以改善用户体验.请随时联系可信商业评论团队.</p>";$htmlContent .= "<p>谢谢</p>";}$htmlContent .= file_get_contents ("email_template_footer.php");$to = $abcd['b_email'];需要'PHPMailerAutoload.php';$mail = 新的 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 = '新图片上传';$mail->Body = $htmlContent;$mail->send();$mail->clearAddresses();}

解决方案

评论不足,所以作为可能的答案:

当我的代码(就像你的)没问题时,我遇到了一连串神秘的解析错误".

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

例如else {

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

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

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

I have been searching on SO for over an hour but couldn't get my issue resolved. For some reason there is error on page as Parse Error: syntax error unexpected } in line 262. It is closing brackets for the else condition.

I removed else condition, the code ran smoothly. Then I reverted back and removed everything inside else condition but still the error is same, I am confused why the closing bracket is unexpected.

Here is the code

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();
}

解决方案

Insufficient points to comment so done as a possible answer:

I had a spate of mystery "parse errors" when my code (like yours) was fine.

In my case it was caused by spurious hidden characters somehow inserted by my PC (OS/browser?) during the copy and paste of example code from web pages.

e.g. else {

If the "space" between "else" and "{" is not actually a "space" then it may cause the subsequent { to be ignored. Result: early termination of the else statement i.e. else $htmlContent .= "<p>Hey,</p>"; the remainder of your conacatenations will be treated as statements outside the else block, and the closing "}" as invalid.

Try deleting your else clause and retype it manually.

If that does not work open up your code in an editor set to show hidden characters. In HTML kit (I think) view->editor->hidden characters will display such characters as solid black as opposed to solid white of space.

这篇关于在 if-else 块中解析错误 Unexpected }的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆