In another thread, while I was helping someone work through an example of dynamic nav, I thought it would be good to mention a couple of things that I do when the code I'm working on goes sideways (breaks). SO...
I build PHP applications in chunks. Partly because I'm not an Uber Geek and partly because it helps in trouble-shooting. I build my apps in logical progressions so that I can test each stage for accuracy, security, speed, as well as whether or not is works. If something does get messed up I tend to use the following rules of thumb.
Is there an error message?
On items like queries to a MySQL database I add
or die("An error occurred in the descriptive name for the query so I know which one choked: ".mysql_error())
This will spit out the error for that query. It helps in getting rid of syntax errors like quotes.
Did the vars get passed?
For code where I'm passing vars on the URL I will place echos at the top of the receiving page to determine whether the var made it. If you're using a link to pass the vars you can accomplish the same thing by simply holding your pointer over the link - the URL should appear.
Is it the function or what I do with the results of the function?
For functions I sometimes bring the code of the function into the file I'm working with and comment out the call to the function. I'll work with the variables until I figure out what I did wrong and then move that code back to the function's file (usually an include of somesort).
You mean that's supposed to loop?
For loops that don't give me the right number of outputs I will test the control.
is what I often use for outputs from multiple record queries. I will echo $num_rows to determine how many it sees. I know what it should be because I use PHPMyAdmin to view the table and/or run a SQL query to get the same results. If the number is right then what I do with the results is broken. If not - then I'm back to the query.
It's supposed to be Jan. 14, 2004 not December 31, 1969
For conversions I often will see if I can at least get an output of somesort. Date's often trip people up - me too - even now. Simple formatting errors are what often get me. Sometimes I use the MySQL formatting to circumvent having to do it in PHP. Other times I simply use PHP's date() function.
Other tips for troubleshooting?