Troubleshooting modification problems

If you're adding modifications or customizations to your Company Website system, here are some general steps you can take to find errors and find solutions:

  1. View error line: If you have errors turned on in PHP on the server, when there is a format error, you'll see a specific message with a line number. Check the following:

    • What is the error? The message should tell you what is wrong.

    • What file is the error in? The message will show you if the error is in an include or in the main file.

    • What line is the error on? Use a text editor with lines (Win32Pad, with the 'Word Wrap' turned off, is a great program) to open the PHP file and look at the error. Use CTRL+G and type in the error line to go right to the line in question.

    • ex.) Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in /home/cowboy/public_html/stconfig.php on line 3
      on the index.php page tells me that the error is in the stconfig.php page on line 3. The "parse error" usually means that there's a punctuation issue - either a missing quote or semicolon, missing dollar sign, too much punctuation, etc.

    • ex.) Warning: include(sbconf/config.php) [function.include]: failed to open stream: No such file or directory in /home/cowboy/public_html/stconfig.php on line 2
      This means that the system could not find the 'config.php' page in the 'sbconf' folder of the site. Usually it means that the file is missing. If the error has the include path:
      Warning: include(/home/cowgirl/public_html/sbconf/config.php) [function.include]: failed to open stream: No such file or directory in /home/cowboy/public_html/stconfig.php on line 2
      this tells us that your PHP code is looking in the "cowgirl" folder (/home/cowgirl/public_html/) when it should be looking in the "cowboy" folder (/home/cowboy/public_html/). In this case, check the file path settings.

    • ex.) Fatal error: Call to undefined function formatsql() in /home/cowboy/public_html/stconfig.php on line 4
      This is telling us that the function 'formatsql' does not exist. If this is a standard PHP function, check to see if your server supports it. Otherwise, if it's a custom function, you need to make sure your code declares it.

  2. Look at the main structure: The page will probably have a main setting towards the bottom of the code, and an action statement at the top. Each may be surrounded by a loop (in PHP, that's { ... }).
    For instance, if you see something like:

    
    

    The part that's at the top (surrounded by the { some code ... }) is the part that's processed when the form is processed. That's where you'll look for errors when the customer clicks the Go button.

  3. When in doubt, use find/replace and copy/paste. When you want to make mods, the easiest way to start is to go through the page and find a field or message. For instance, if you want to change the wording "Price:" to "Retail:", you can use CTRL+F to find the text "Price:" and change to "Retail:". Or you can copy entire lines and paste where you want it in the form - just make sure to change the field names!
    To search through the entire script, a really handy search program is Free Byte's Hard Disk Search. Just load the program, then type the text you want, select the folder on your computer that has the whole script, and in seconds the system will show you which file that text is in!

  4. Compare programs. Not sure what's been changed? Use a file changer like Win Merge to compare the original with your modified version to highlight the changes.

  5. Try a die() statement: If you can't track down the error, add the statement:

    die();

    anywhere in the PHP code. This will stop the page from processing at that point in the code. This is especially helpful for troubleshooting errors with includes - add the die statement above the first include, and see if the error persists. Continue moving it below each include until the error comes out.

  6. Use PHP tools: Can't figure out your system path? Temporarily add the PHP code:

    echo $_SERVER['DOCUMENT_ROOT'];

    under the PHP.net.

  7. Force a script error: Add a line of incorrect code, such as the xxx in the following example:

    
    

    to the script temporarily to force a die. This is a great way to show the system path, if the document_root doesn't show it.

  8. Show the variables: If you can't find the error, try showing variables. For instance, if you have a page that shows:

    
    

    You can add a statement:

    die ("Name: $name");

    Just under the $name statement. That will parse the page and force the name variable to show, so you can make sure it's showing correctly.

  9. Think about server settings: Are register_globals enabled? If so, you might not be able to use short variables (ie. $variable, vs. $_POST['variable']). If register_long_arrays is enabled, you can use $HTTP_POST_VARS['variable'] - but if it is disabled you must use the short arrays.