Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP Build a Simple PHP Application Wrapping Up The Project Using A Third-Party Library

Nazan Gökbulut
PLUS
Nazan Gökbulut
Courses Plus Student 3,910 Points

It throws a syntax error on my closing curly backet "}" of the if-Statement

It throws this error message: "Parse error: syntax error, unexpected '}' in C:\xampp\htdocs\contact.php on line 46" If i delete the curly bracket, it throws another error and if i add an curly bracket it shows me the same error message.

Could you please help me and tell me my fault ?

Here is the if-statement at the beginning of the contact.php file:

<?php

if ($_SERVER["REQUEST_METHOD"]== "POST") {


    $name=trim($_POST["name"]);
    $email=trim($_POST["email"]);
    $message=trim($_POST["message"]);

        if($name == "" OR $email == ""  OR $message=="" ){

            echo "You must specify a value for name, email address and message.";
            exit;
        }

        foreach( $_POST as $value){
            if( stripos($value, 'Content-Type:') !== FALSE)

                echo "This was a problem with the information you entered.";
                exit;
            }
        }

        if($_POST["address"] != "") {
            echo "Your form submission has an error.";
        }

    require_once("inc/phpmailer/class.phpmailer.php");
    $mail  = new PHPMailer();

        if(!$mail->ValidateAddress($email) ){
            echo "You must specify a valid email address.";

        }

    $email_body="";
    $email_body=$email_body . "Name: ".$name."\n";
    $email_body=$email_body . "E-Mail: ".$email."\n";
    $email_body=$email_body . "Message: ".$message."\n";

    // TODO: Send Email

    header("Location: contact.php?status=thanks");
    exit;

}   
?>

<?php

$pageTitle = "Contact Mike";

2 Answers

Hi Nazan,

Not sure if this is what is causing the error but this line looks to be missing an opening curly bracket:

if( stripos($value, 'Content-Type:') !== FALSE)

Hope that helps

-Rich

Nazan Gökbulut
PLUS
Nazan Gökbulut
Courses Plus Student 3,910 Points

It worked! It seems like i've missed it. Thank you very much!

-Nazan

No problem :)