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 Adding a Contact Form Working with Get Variables

Nicole Solis
Nicole Solis
14,469 Points

Contact form no longer displaying after including the if/else statement

After going through the videos again and searching my code, I'm still not sure why I only load the h1 Contact and nothing else functions afterwards. Does anything jump out as wrong?

<?php 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 . "\n";

// TODO: Send Email

header("Location: contact.php?status=thanks"); exit; } ?><?php $pageTitle = "Contact Mike"; $section = "contact"; include('inc/header.php'); ?>

<div class="section page"> <div class="wrapper"> <h1>Contact</h1>

<?php if (isset($_GET["status"]) AND $_GET["status"] == "thanks") { ?>
  <p>Thanks for the email! I&rsquo;ll be in touch shortly.</p>
<?php> } else { ?>

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

</div> </div>

<?php include('inc/footer.php') ?>

2 Answers

Logan R
Logan R
22,989 Points

Do you get an error? I noticed at your else block:

<?php> } else { ?>

That you have

instead of ```<?php```. I would try changing that and see if that makes any difference.
Nicole Solis
Nicole Solis
14,469 Points

WHY!?? Seriously, I freaked out for around half an hour yesterday because I had written funtion instead of function and didn't see it until I had researched the h*** out of everything else. Thank you btw! :)

Logan R
Logan R
22,989 Points

No problem :) Hope you get it to work!

Try throwing this:

<?php

error_reporting(-1);
ini_set('display_errors', 'On');

right at the beginning of your code - it should show you syntax errors and stuff making debugging like this super quick!

Nicole Solis
Nicole Solis
14,469 Points

Oooooo...this is super awesome! Ty!