0

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();
}
Piyush Rawat
  • 135
  • 9
  • The code you have posted generates no parse error so the problem must be somewhere else. – jeroen Oct 06 '17 at 07:29
  • strange...i am seeing it right in front of me.. – Piyush Rawat Oct 06 '17 at 07:30
  • For syntax error like brackets it's not always that line no is same. It must be breaking above this code somewhere. – shyammakwana.me Oct 06 '17 at 07:32
  • yes i understand it could be in above lines, but if I completely remove else condition it works fine, and if I remove all the code inside else condition then it doesn't work. – Piyush Rawat Oct 06 '17 at 07:34
  • I can't see any error in there either. But You shouldn't be using data from user request in a database query without validating it first – Radek Suski Oct 06 '17 at 07:39
  • i can't see myself, but it's showing on the output page. searching for over an hour and still not successful – Piyush Rawat Oct 06 '17 at 07:41
  • @PiyushRawat : error may be with the data which is from db. so first check the data u r passing. – SNG Oct 06 '17 at 07:43
  • @Sucharitha...db values are fine, i am surprised it doesnt work even if i remove everything inside else condition, but works when I completely remove the else condition – Piyush Rawat Oct 06 '17 at 07:50

1 Answers1

2

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.

scytale
  • 1,339
  • 1
  • 11
  • 14
  • You were right, there were some invisible characters near the closing bracket. I removed them and it worked like a charm. – Piyush Rawat Oct 06 '17 at 09:37