Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP

Katie Charles-McGrath
Katie Charles-McGrath
1,823 Points

Getting "Parse error: syntax error, unexpected ';' in /home/treehouse/workspace/suggest.php on line 3"

I know this is going to be something obvious, but I've compared my code to the download code and as far as I can tell, my code is exactly the same as Alena's.

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
  $name = $_POST["name"];
  $email = $_POST["email"];
  $details = $_POST["details"];

  echo "<pre>";
  $email_body = "";
  $email_body .= "Name " . $name . "\n";
  $email_body .= "Email " . $email . "\n";
  $email_body .= "Details " . $details . "\n";
  echo $email_body;
  echo "</pre>";

  //To Do: Send Email
  header("location:suggest.php?status=thanks");
}

$pageTitle = "Suggest a Media Item";
$section = "suggest";

include("inc/header.php"); ?>

<div class="section page">
    <div class="wrapper">
        <h1>Suggest a Media Item</h1>
        <?php if (isset($_GET["status"]) && $_GET['status'] == "thanks") {
            echo "<p>Thanks for the email! I&rsquo;ll check out your suggestion shortly!</p>";
        } else {
        ?>
        <p>If you think there is something I&rsquo;m missing, let me know! Complete the form to send me an email.</p>
        <form method="post" action="process.php">
            <table>
            <tr>
                <th><label for="name">Name</label></th>
                <td><input type="text" id="name" name="name" /></td>
            </tr>
            <tr>
                <th><label for="email">Email</label></th>
                <td><input type="text" id="email" name="email" /></td>
            </tr>
            <tr>
                <th><label for="name">Suggest Item Details</label></th>
                <td><textarea name="details" id="details"></textarea></td>
            </tr>
            </table>
            <input type="submit" value="Send" />
        </form>
        <?php } ?>
    </div>
</div>

<?php include("inc/footer.php"); ?>

Can anyone see something I don't?

Hi Katie,

Can you post a snapshot to your workspace? Right now I'm not seeing an issue.

Katie Charles-McGrath
Katie Charles-McGrath
1,823 Points

Here's a link to the snapshot (I think that's how this works):

https://w.trhou.se/xghc2o80f9

The suggest.php file in question is the one now called kt_suggest.php. I renamed it and replaced it with the downloaded version so that I could move on with the course.

Thank you!

2 Answers

The code you posted in your question must have been the corrected code because it's different from what you have in kt_suggest.php

You have a misplaced bracket and missing parenthesis to close off the if condition in kt_suggest.php

Compare the following:

// from kt_suggest.php
if ($_SERVER["REQUEST_METHOD" == "POST"] {
// corrected code
if ($_SERVER["REQUEST_METHOD"] == "POST") {

I forked your workspace and made that change and your page seems to be displaying correctly.

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,692 Points

Hey Katie,

The code you have posted in the question here doesn't appear to have any syntax error; however, in your Workspace snapshot, the file kt_suggest.php does have a misplaced closing square bracket in the opening line of code.

It reads

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

but should read

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

The error will be thrown on the following line from where the actual error is (usually). It wasn't until the compiler got to the semi-colon on line three that it realized something wasn't right. It reached a statement end, but didn't have a valid statement.

The square brackets are pointing to an index in the array, so with the closing bracket after post, the compiler is looking for an index named "REQUEST METHOD" == "POST" instead of comparing the index value against "POST".

I hope this makes sense. Keep Coding! :dizzy: