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
Matthew Willmott
9,426 PointsWorking with Get Variables
On the final video of the Adding a Contact Form section, I am writing the code that Randy is writing towards the end of the video. The problem has started to occur once writing the section on checking the $_GET status.
Somewhere an error is stopping the contact page from displaying anything at all, and I can't spot it. So to avoid me being stuck on this forever, I ask for some help in spotting the (probably stupidly simple) mistake/typo I've made which is causing the blank screen. Here is the code:
<?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;
//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'll be in touch shortly.</p>
<?php } else { ?>
<p>I’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">
</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 'inc/footer.php'; ?>
1 Answer
Matthew Mascioni
20,444 PointsI'm no expert at PHP, but one thing I noticed right off the bat, in the beginning of your code:
header("Location: contact.php?status=thanks")
You need to place a semicolon at the end of that line. Consequently, it looks like that line is what's setting your GET variable (or one of them)
Hope this helps!
Matthew Willmott
9,426 PointsMatthew Willmott
9,426 PointsSuper stuff, I knew it something as simple as that but after looking for so long you can't see anything. Thank you very much :)