If your application/script is not working as expected and you're not sure why, a great way to debug this would be to enable error reporting in PHP through your htaccess. Add the following lines to your .htaccess file:
php_flag display_errors on
php_value error_reporting "E_ALL & ~E_STRICT & ~E_NOTICE"
This will display errors from your PHP sites/applications to help debug any error(s) you're running into.