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

lyonel scapino
lyonel scapino
14,191 Points

Add a form : Parse error unexpected curly braces

I get this error message. Still, my code is exactly the same as the video's.

Parse error: syntax error, unexpected '{' in C:\xampp\htdocs\contact.php on line 33

```<div class= "wrapper"> <h1 align="center">Contact</h1>

    <?php if ((isset($_GET["status"]) AND $_GET["status"] == "thanks") { ?>

        <p> Thanks for your email, I&rsquo;ll be in touch!  </p>

       <?php } else {  ?>

    <p>I&rsquo;d love to hear from you! Please complete the form below. </p>
    <form method="post" action="contact.php">```

14 Answers

In your first line you have 3 opening parentheses and 2 closing it. Get rid of the first opening one. Tell me if that was it.

lyonel scapino
lyonel scapino
14,191 Points

Thanks, still gets me a loop redirection error message from Chrome.

Is this all your code for this page? Cause you are missing the closing curly braces at the end of the code.

<?php } ?>

it would close your else serie of actions.

lyonel scapino
lyonel scapino
14,191 Points

no I got this at the bottom of the page under the form closing tag.

lyonel scapino
lyonel scapino
14,191 Points

```<?php } else { ?>

    <p>I&rsquo;d love to hear from you! Please complete the form below. </p>
    <form method="post" action="contact.php">
        <table>
                <tr>
                    <th>
                <label for="name">Name</label>
                    </th>
                    <td>
                    <input type="text" name="name" id="name">
                    </td>
                </tr>
                <tr>
                    <th>
                <label for="email">Email</label>
                    </th>
                    <td>
                    <input type="text" name="email" id="email">
                    </td>
                </tr>
                <tr>
                    <th>
                <label for="message">Message</label>
                    </th>
                    <td>
                    <textarea  name="message" id="message"></textarea>
                    </td>
                </tr>
        </table>
        <input type="submit" value="Send">
    </form>
    <?php } ?>```
lyonel scapino
lyonel scapino
14,191 Points

Here is the entire page I find it weird (I've erased the isset function for now for test purposes)

if ($_SERVER["REQUEST_METHOD"]  == "POST") {
    $name = $_POST["name"];
    $email = $_POST["email"];
    $message = $_POST["message"];
    $email_body = "";

    $email_body = $email_body . "Name: " . $name . "\n";
    $email_body = $email_body . "Email: " . $email . "\n";
    $email_body = $email_body . "Message: " . $message;
    echo $email_body;

}
// TODO : SEND EMAIL

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


?>
<?php 
$pageTitle = "Contact Mike";
$section = "contact";

include('Include/Header.php'); ?>

<div>

    <div class= "wrapper">
        <h1 align="center">Contact</h1>

        <?php if ( $_GET["status"] == "thanks") { ?>

            <p> Thanks for your email, I&rsquo;ll be in touch!  </p>

    <?php   } else { ?>         


        <p>I&rsquo;d love to hear from you! Please complete the form below. </p>
        <form method="post" action="contact.php">
            <table>
                    <tr>
                        <th>
                    <label for="name">Name</label>
                        </th>
                        <td>
                        <input type="text" name="name" id="name">
                        </td>
                    </tr>
                    <tr>
                        <th>
                    <label for="email">Email</label>
                        </th>
                        <td>
                        <input type="text" name="email" id="email">
                        </td>
                    </tr>
                    <tr>
                        <th>
                    <label for="message">Message</label>
                        </th>
                        <td>
                        <textarea  name="message" id="message"></textarea>
                        </td>
                    </tr>
            </table>
            <input type="submit" value="Send">
        </form>
        <?php } ?>

    </div>
</div>

<?php include('Include/Footer.php'); ?>```

What does the error message says exactly?

lyonel scapino
lyonel scapino
14,191 Points

this webpage has a redirect loop

on chrome. apparently it has to do with pages calling themselves...

Quite hard to help you like that, I admit. Sorry. What I could say to help is this:

Save a copy of your file contact.php (for reference, and have an original). With the active php file:

  1. Try to remove everything but your includes of header and footer. Test it
  2. Try to remove every part of it to isolate where the error appears. And test every part.

When I say remove, you can remove it or set it as comments, of course.

lyonel scapino
lyonel scapino
14,191 Points

Actually my problem lies in the Header and Exit commands. when I deactivate I get back the contact form but unfortunately if i fill it up it does go to the thanks message.

At least you know where the problem lies :). Keep us informed ^^.

lyonel scapino
lyonel scapino
14,191 Points

Yea well I've done that and still get the error so I think it might have to do with the general structure and a missing statement at the beginning of the page. Many thanks anyway.

lyonel scapino
lyonel scapino
14,191 Points

i finally got it!!! the problem was that my curly closing braket was before and not after the header and exit commands!!! What a f****r am I??? :) I feel like I am blind or something. THANKS ANYWAY!!!!!!!!!!

Glad you found it, frustrating, but hey, you did find it, and you got experience as well as the satisfaction to control perfectly your code ^^, fair enough, no? :D.

lyonel scapino
lyonel scapino
14,191 Points

Man,you re pretty advanced....only in a few months..and you already sound like you re working for treehouse or sthg...lol :)

What is a sthg? :)

And for you to know, it was question of survival. I was unemployed, searching on the net to understand by myself web programming...and then, found Treehouse on youtube. Didn't know if it would be a good decision to pay...2 days later, debuting my adventure here. And I devoured the courses, amazed before every video, discovering the languages, but in the same time getting answers about a lot of questions I was wondering about...

2 months later, I got a positive reply from an employer, and I started as a webmaster since december. Treehouse gave me the chance I needed ^^. Well, I didn't get a super job neither :D, it's only a part-time job, but it's a start, and it gives me experience, and I have a job I like a lot ^^.

I could talk a lot about this, but that's not the place. What I can say, is, as long as you are persistent, and have a bit of patience, with time everything seems easier, and you can go further, to new adventures! (I ended the Objective C basics courses today, and I don't intend to be a iOS developer, but it's included in the price, so why don't look at it as well? :D).

lyonel scapino
lyonel scapino
14,191 Points

Amazing story Giovanni, where are you from? I have no plans of becoming a webmaster, but who knows? I would not dislike the experience I believe. I agree the site is quite cool and I hope I can get up to the iOS dev part cause it would be awesome for me to develop that kind of apps. I am also interested in the design part actually, My ultimate objective would be to be fully autonomous IT/design wise. I partly took this course out of disappointement on IT deliveries to be honest and thinking it could not be so complicated (to fall in such delays...) and the more I study the more I feel like there is abuse in the profession (I know I am speaking very frankly here) and I cannot wait to be really autonomous or at least know exactly the worth of each type of effort and so on. I also partly took this course cause I feel like I am learning to read, I feel this century will be the one of the digital fracture like reading was during last century and I know what side I want to be on... I hope I'll see you around on the site, even though I see no social media buttons around :) Again very cool story. I believe the internet gives to all people education chances like never before. And you Giovanni and Treehouse are just perfect examples.

Cheers!

I am from île de la Réunion, a small island near Mauritius island (East of Madagascar). It's a french outerland territory.

What do you mean by abuse in the profession?

When you say you are interested in the design part, do you actually practice digital graphics or similar?

lyonel scapino
lyonel scapino
14,191 Points

I've had severe delays on several projects that I specified (very precisely). I still don't know today if it was for lack of competences or lack of seriousness (like taking the money and working on something else) because these projects were outsourced and I did have access to the developers.

For the design part, I have created some designs in the past but I just want to be fully operational on photoshop and so on.

Well, I believe that in the majority, it's a lack of competences (and maybe a bit of seriousness, but due to the lack of competences :P). I say it because I had the same experience, but from the other point of view.

It happened a few times in the past, were I had opportunities to encounter potential clients. They had a project, criterias and all...and I thought I was capable of doing it! But a half-knowledge is more dangerous than no knowledge at all. You always say yes, because you don't know if you can really do it, but you think that internet will give you a magical shortcut to do it, and you will be able to be back on your feet. Wrong!

You try, despair, and finally you know that you didn't do a good job. The client is, of course, not satisfied (well, I wasn't paid for it, so no big deal for them). Personnaly it affects me, I hate to "not be able to". That's when I got consciousness of what I lacked: experience of course, but solid basics, and to accept that I can't do everything, even if I want. I needed priorities.

I started back from scratch, and was determined to "know what I am doing" before accepting anything. That's when I was lucky to discover Treehouse at this exact same time.

And you know what, I learned a lot more than I was expecting to find here ^^.

Some good examples are:

There are others (I leave you to look for it), but those were really helpful. That's some extra knowledge I needed, and it got me nice experiences. I met new partners, who like what I did and could do (and not what I would do or might do), and I was "able to" do what they needed. Great bonus for self-estim, and solid partnerships for the future.

If you have the opportunity, a good way to develop solid partnerships is events like the Startup Week End. In my case it's a good place to develop a network, meet interesting people to exchange and create partnerships, and even more, to see "in real time" on a (fictive) project what your potential partners are capable of.

lyonel scapino
lyonel scapino
14,191 Points

That might be the right view, programming might be more difficult than it appears in many cases. My doubt is that in both cases it was supposed to be trained and educated professionals. Anyway, I like your approach of Treehouse.