2017-10-06 51 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

你是對的,有一些看不見的字符附近的括號。我刪除了它們,它像魅力一樣工作。 –