$fields is undefined - custom theme creation
The $fields variable will be available for theming only if you have selected to display fields  instead of content, check under format section of view.    

Secondly, the $fields variable is not available if your template file is views-view.tpl.php, you have to use views-view-field.tpl.php or if you want theme only a specific field, you can use views-view-field--fieldname.tpl. php.