Troubleshooting PHP Errors and Syntax


Troubleshooting PHP Errors and Syntax

When using PHP, you will often need to troubleshoot scripts to find and fix errors. Two very popular methods for which to do so are to use echo statements and the die() function.

The echo statement will print out text so you can pinpoint what works and what does not. Echo statements can be used to troubleshoot an entire script or functions. Not only do echo statements help you find where problems exists, they can be very valuable to print out arrays and variables made from relational database queries. This can help find many sysntax problems and saves lots of troubleshooting time.  

The die() statement can be used with text. The die statement will stop the script and output the text inside its parenthesees.
Example:

Common trouble shooting techniques:

die("If you are a non-member the script stops here!");

print_r($myarray);

echo $row['name'];
echo "hello does this print?";