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 Basic PHP Website (2018) Adding a Basic Form Checking the Request Method

Martina Carrington
Martina Carrington
15,754 Points

Error on Suggest.php

Hi! i received this error message on suggest.php ;Parse error: syntax error, unexpected 'echo' (T_ECHO) in /home/treehouse/workspace/suggest.php on line 9

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

  echo "<pre>";
  $email_body = "";
  $email_body .= echo "Name " . $name . "\n";
  $email_body .= echo "Email " . $email . "\n";
  $email_body .= echo "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"></div>
    <h1>Suggest a Media Item</h1>

  <?php if(isset($_GET["status"])&& ($_GET["status"] == "thanks") {
  echo "<p>if you think there is somthing I&rsquo;'m missing, let me know! Complete the form to send email.</p>";
} else{ ?>

<form method="post" action="suggest.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"); ?>

3 Answers

Hi Martina!

Try removing each of the 'echo' statements that you have gotten on lines 9, 10 and 11. Echo is the statement that is used to print out values and this shouldn't be needed when you are concatenating things into a string to be stored in a variable.

Try this out and let me know if you need any more help!

Martina Carrington
Martina Carrington
15,754 Points

Hi Luke Glazebrook , now it say i have error on line 29 . i did a double check see double echo 's echo "<p>if you think there is somthing I’'m missing, let me know! Complete the form to send email.</p>"; } else{ ?>

Humberto Jiménez Olea
Humberto Jiménez Olea
4,027 Points

Hi Martina,... please check if you close your else block below the label form...

</form> <?php } ?>

regards. :-)

Humberto Jiménez Olea
Humberto Jiménez Olea
4,027 Points

Hi Martina:

Mr. Luke this is right, check and try this...

            $email_body .= "Nombre: " . $name . "\n";

Regards.

Martina Carrington
Martina Carrington
15,754 Points

Humberto Jimenez Olea , now i have error on line 29 echo "<p>if you think there is somthing I’'m missing, let me know! Complete the form to send email.</p>"; } else{ ?>