Don’t try to do everything at once. Write a little bit of code, then test it. Write a little bit more, and test it again. Don’t start writing a full page of code and expect it to run. When errors happen, it’s a lot easier to solve them if you know where they are happening.
Put comment “traffic cones” in your code to narrow down problem areas. Comments in PHP are exactly the same as those in CSS: i.e.
<?php This code will be run;
/* this code will be ignored (multiple lines) */
// this code (a single line) will be ignored too
# this code (again on a single line) will also be ignored
If you are taking a class with me, I will not respond to cries of “it doesn’t work”. Before I can help you I expect you to tell me where the code doesn’t work, by eliminating suspect code inside comments. In doing so, you’re likely to find the cause of the problem yourself.
Keep in mind that the PHP parser is sometimes inaccurate when reporting the locations of errors. Sometimes it will report “Error on line 1” when the error isn’t on line 1 at all (in fact this error usually indicates that a brace has not been closed correctly).
Close code correctly. Problems coding HTML are usually due to incorrectly written tags and incorrectly closed tags. If this is the source of most of your errors in HTML, the same problems will continue to haunt you when coding PHP.
Estimated reading time: 1 minute, 15 seconds