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

Desmond Dallas
Desmond Dallas
6,985 Points

PHP error 500

Can anyone please tell me what is wrong with this code. Also I am using the developer tools but does not show me line of error like Javascript. The page just goes blank. Do you know why?

<?php

$name = $_POST['firstname'] . ' ' . $_POST['lastname']; $when_it_happened = $_POST['whenithappened']; $how_long = $_POST['howlong']; $how_many = $_POST['howmany']; $alien_description = $_POST['aliendescription']; $what_they_did = $_POST['whattheydid']; $fang_spotted = $_POST['fangspotted']; $email = $_POST['email']; $other = $_POST['other'];

$to = 'owen@aliensabductedme.com'; $subject = 'Aliens Abducted Me - Abduction Report'; $msg = $name was abducted $when_it_happened and was gone for $how_long.\n" . "Number of aliens: $how_many\n" . "Alien description: $alien_description\n" . "What they did: $what_they_did\n" . "Fang spotted: $fang_spotted\n" . "Other comments: $other"; mail ($to, $subject, $msg, 'From:' . $email);

echo 'Thanks for submitting the form.<br />'; echo 'You were abducted for ' . $when_it_happened; echo ' and was gone for ' . $how_long . '<br />'; echo 'Number of aliens: ' . $how_many . '<br />'; echo 'Describe them: ' . $alien_description . '<br />'; echo 'The aliens did this: ' . $what_they_did . '<br />'; echo 'Was Fang there? ' . $fang_spotted . '<br />'; echo 'Other comments: ' . $other . '<br />'; echo 'Your email address is ' . $email;

Adam Doe
Adam Doe
30,840 Points

Check the concatenation on your $msg string. You need to to add quotations around text that isn't variables to create proper strings and use periods in between your strings and variables. Hopefully this helps :)

Desmond Dallas
Desmond Dallas
6,985 Points

It worked thanks. However Im still not sure how to check errors when the screen goes blank and developer tools seems to be of little help, unless Im not using it correctly. Do you have any suggestions.

2 Answers

Adam Doe
Adam Doe
30,840 Points

An easy way to troubleshoot errors is to var_dump() what you're working on. In your case, var_dumping your $msg variable would have given you an error. There are also a number of error notifications that can be configured depending on what server you're using and error logs that can be set up. On a simple install of a WAMP server I could see that you had an error on line 15 where your $msg variable was. I believe there are a number of videos on here for troubleshooting PHP errors so try looking into those :)

http://php.net/manual/en/function.var-dump.php

Desmond Dallas
Desmond Dallas
6,985 Points

Thank you, very helpful