I'm a self taught PHP programmer and one of the most important discoveries I made was assertions. Assertions simply ensure that the variables you're using are what you expect. If they're not, the script dies immediately.

Consider the following:

Code:
function InsertRowIntoTable($_TableName,$_ArrayOfFieldNamesAndValues)
{
    assert('is_array($_ArrayOfFieldNamesAndValues)');
    assert('!empty($_ArrayOfFieldNamesAndValues)');

    foreach ($_ArrayOfFieldNamesAndValues as $_FieldName => $_FieldValue)
    {
        assert('strlen($_FieldName) > 0');
        assert('FieldExistsInTable($_TableName,$_FieldName)');
        // you would have to create FieldExistsInTable()
    }

    // If no assertions occur, it's OK to execute
    // the INSERT commands (but don't forget to sanitize!)

}
This may seem obvious to you and you may think that "Oh I know what the values are going to be, this isn't necessary" but TRUST ME this is the quickest & easiest way to find bugs before they occur. It's a great way to know that you product will have less bugs when shipped.

Note: You can and should disable assertions in a production environment. The way I do it is I enable them for my IP but turn them off for everyone else.