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
Phil Rice
5,536 PointsStrange problem with indenting PHP code
I spent hours last might trying to work out why a php page i was working on wasnt working and I have finally found out what seemed to be causing it this morning but I dont understand why it would do so.
Basically the page im working on it code taken from a book " learning PHP, MySQL, Javascript and CSS by O Reilly second edition." and it was " a practical example" on how to use PHP to connect to a MY SQL db, list out the records and also provide ability to add new records and delete current ones. I edited the code to reflect my own DB and spent hours trying to make it work but it simply gave me a error page (HTTP Error 500 (Internal Server Error):). I checked the code so many times for typos and errors and finally went to bed in the small hours of the morning. This morning I started a new and this time used a downloaded copy of the code from the authors website (I hand typed all the code first time), reedited it for my DB and it worked first time. That would suggest that I made an error in my code first time I thought. So I continued to add in the header and footer, div wrapper etc , all working fine and then finally to make it look nicer I thought I would indent all of the php code that talked to the DB . This is when I got the server error again - when indenting the code! I didnt change any code at all , just indented it one tab space and it breaks the whole page. I unindent it and it works again. How can this be?
Im using sublime text 2 - im now wondering if this is a bug or am i missing something?
2 Answers
Randy Hoyt
Treehouse Guest TeacherAdding a tab shouldn't matter, but I can think of a couple of ways offhand that it might. It very depends on what the code is doing. Would you mind posting the problematic code?
Phil Rice
5,536 PointsRandy Hoyt - sorry for the late reply , been a bit busy last few days so not been on here much.
I dont have the original code to paste anymore as I have changed things since then but I think I might have tracked down what it was just this second.
I tried indenting the _END of a <<<_END heredoc pair and found that it breaks it (as im sure your well aware - I wasnt !). I checked out the heredoc documentation at php.net and it says "The closing identifier must begin in the first column of the line." There was a heredoc pair in the code so it would deffo have broken things.
So ive learnt something new and everything turns out fine!