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
Chris Metcalf
788 PointsWorking with variables PHP Contact page crashes
Hi, I am currently stuck. I have made all of the changes in the final video of this section and the contact page no longer loads just crashes with a white screen......Everything was working fine until I started adding the IF statement and running everything from the contact.php page instead of the contact-thanks.php page. I have tried re-writting everything from scratch, to no avail.....pleases help. I have pasted the code from the contact.php page below.
Hope you can help
Best regards
Chris M
<?php
if ($_SERVER)["RESQUEST_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;
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="name">Email</label>
</th>
<td>
<input type="text" name="email" id="email">
</td> </tr>
<tr> <th>
<label for="name">Message</label>
</th>
<td>
<textarea type="text" name="message" id="message"></textarea>
</td> </tr>
</table> <input type="submit" value="Send">
</form>
<?php } ?>
</div>
</div>
<?php include ('inc/footer.php'); ?>
9 Answers
Randy Hoyt
Treehouse Guest TeacherIf you have a white screen, it means you have some invalid PHP. It looks like this line ...
if ($_SERVER)["RESQUEST_METHOD"] = "POST" {
... should be written like this:
if ($_SERVER["REQUEST_METHOD"] == "POST") {
Does that help?
Chris Metcalf
788 PointsHi Randy,
Thanks for your quick reply.
I have tried adding the extra = sign and it still doesn't work, I get the white screen in Safari and Firefox and this message in chrome:
Server error The website encountered an error while retrieving http://localhost/htdocs/contact.php. It may be down for maintenance or configured incorrectly. Here are some suggestions: Reload this webpage later.
HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request.
As I said everything was working fine until I started trying to run everything from the contact page.
Kevin Murphy
24,380 PointsHey Chris, I noted that Randy's comparison above also changes the spelling from RESQUEST to REQUEST_METHOD. Your reply above only indicates that you changed the number of equal signs. Just a fresh eyes perspective if that's of help.
Randy Hoyt
Treehouse Guest TeacherThere must be another piece of invalid PHP. I'll take a look a little later today. More soon ...
Randy Hoyt
Treehouse Guest TeacherIt looks like you don't have the right number of parentheses here:
<?php if (isset($_GET["status"]) AND ($_GET["status"] == "thanks") { ?>
You don't need one in front of the second $_GET:
<?php if (isset($_GET["status"]) AND $_GET["status"] == "thanks") { ?>
Does that help?
Chris Metcalf
788 PointsNo, still not working. :(
Randy Hoyt
Treehouse Guest TeacherTry downloading the code attached to the project to see if that works.
Chris Metcalf
788 PointsYeah replaced the code with the project files and it worked like a charm, I am OK with HTML and CSS but I don't think my PHP Skillz will pay the bills :) any way I will crack on....
Thanks for all your help and such a rapid response.
Randy Hoyt
Treehouse Guest TeacherCool. I would recommend opening two tabs in your text editor, one with your code and one with my code. Then flip back and forth between them and watch for minor differences.
If that doesn't work, try adding lines of code more slowly and then refreshing. Add a conditional here and then refresh to make sure it doesn't have a syntax error. Add another line and check it again. If you miss a semi-colon or get a set of parentheses in the wrong order, you'll know right away which line of code causes the problem.
Chris Metcalf
788 PointsThanks Randy, Thats great advice. I will try doing that in my next round of coding exploits.