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 Utilizing Object Properties and Methods

jinhwa yoo
jinhwa yoo
10,042 Points

help me

Parse error: syntax error, unexpected '<' in /home/treehouse/workspace/suggest.php on line 58

<?php

if($_SERVER["REQUEST_METHOD"] =="POST"){ $name = trim(filter_input(INPUT_POST, "name", FILTER_SANITIZE_STRING)); $email = trim(filter_input(INPUT_POST, "email", FILTER_SANITIZE_EMAIL)); $details = trim(filter_input(INPUT_POST, "details", FILTER_SANITIZE_SPECIAL_CHARS));

if($name == "" || $email == "" || $details ==""){ echo "please fill in the required fields: Name , Email and Detials"; exit; }

if($_POST["address"] != ""){ echo "Bad form input"; exit; } require("inc/phpmailer/class.phpmailer.php"); $mail = new PHPMailer; if($mail->ValidateAddress($email)){ echo "Invalid Email address"; exit; }

$email_body=""; $email_body .= "Name " . $name . "\n"; $email_body .= "Email " . $email . "\n"; $email_body .= "Details " . $details . "\n";

$mail->setFrom($email, $name); $mail->addAddress('treehouse@localhost', 'Alena'); // Add a recipient

$mail->isHTML(false); // Set email format to HTML

$mail->Subject = 'Personal Media Library Suggestion' . $name; $mail->Body = $email_body;

if(!$mail->send()) { echo 'Message could not be sent.'; echo 'Mailer Error: ' . $mail->ErrorInfo; exit; }

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"){ <p>Thanks for the email! I’ll check your suggestion shortly!</p>; } else { ?> <p>If you think there is something I’ missing, let me know! complete the form to send me an email!</p> <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="details">Suggest Item Details</label></th> <td><textarea name="details" id="detials"></textarea></td> </tr> <tr style="display:none"> <th><label for="address">Address</label></th> <td><input type="text" id="address" name="address" /></td> </tr> </table> <input type="submit" value="send" /> </form>
<?php } ?> </div> </div>

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

Simon Coates
Simon Coates
28,694 Points

no. you can use echo or <?php ?>. not both.

<?php if(isset($_GET["status"]) && $_GET["status"] == "thanks"){?>
 <p>Thanks for the email! I’ll check your suggestion shortly!</p>
<?php } else { ?><p>if you think of  </p>

2 Answers

Simon Coates
Simon Coates
28,694 Points
if(isset($_GET["status"]) && $_GET["status"] == "thanks"){ <p>Thanks for the email! I’ll check your suggestion shortly!</p>; }

You go straight into html without closing the PHP instruction with ?>

jinhwa yoo
jinhwa yoo
10,042 Points

I don't get it ////

plz show where i fix ?

Simon Coates
Simon Coates
28,694 Points

$_GET["status"] == "thanks"){ <p>Thanks for the email! I’ll check your suggestion shortly!</p>; } else { ?> <p>If you think

should be

$_GET["status"] == "thanks"){ ?><p>Thanks for the email! I’ll check your suggestion shortly!</p><?php } else { ?> <p>If you think

of should use the echo command like:

{ echo "<p>Thanks for the email! I’ll check your suggestion shortly!</p>"; } else {

jinhwa yoo
jinhwa yoo
10,042 Points

<?php

if($_SERVER["REQUEST_METHOD"] =="POST"){ $name = trim(filter_input(INPUT_POST, "name", FILTER_SANITIZE_STRING)); $email = trim(filter_input(INPUT_POST, "email", FILTER_SANITIZE_EMAIL)); $details = trim(filter_input(INPUT_POST, "details", FILTER_SANITIZE_SPECIAL_CHARS));

if($name == "" || $email == "" || $details ==""){ echo "please fill in the required fields: Name , Email and Detials"; exit; }

if($_POST["address"] != ""){ echo "Bad form input"; exit; } require("inc/phpmailer/class.phpmailer.php"); $mail = new PHPMailer; if($mail->ValidateAddress($email)){ echo "Invalid Email address"; exit; }

$email_body=""; $email_body .= "Name " . $name . "\n"; $email_body .= "Email " . $email . "\n"; $email_body .= "Details " . $details . "\n";

$mail->setFrom($email, $name); $mail->addAddress('treehouse@localhost', 'Alena'); // Add a recipient

$mail->isHTML(false); // Set email format to HTML

$mail->Subject = 'Personal Media Library Suggestion' . $name; $mail->Body = $email_body;

if(!$mail->send()) { echo 'Message could not be sent.'; echo 'Mailer Error: ' . $mail->ErrorInfo; exit; }

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’ll check your suggestion shortly!</p>";
  <?php } else { ?><p>if you think of  </p>


  <p>If you think there is something I&rsquo; missing, let me know! complete the form to send me an email!</p>
  <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="details">Suggest Item Details</label></th>
           <td><textarea name="details" id="detials"></textarea></td>
        </tr>
      <tr style="display:none">
           <th><label for="address">Address</label></th>
           <td><input type="text" id="address" name="address" /></td>
        </tr>
    </table>
   <input type="submit" value="send" />
  </form>  
   } 

</div> </div>

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